All Scripting Elements : Scriptlet « JSP « Java Tutorial






<%@ page language="java" contentType="text/html" %>
<%@ page import="java.util.Date" %>
<%!
  private String getGreeting() {
    Date now = new Date();
    String greeting = null;
    if (now.getHours() < 12) {
      greeting = "Good morning";
    }
    else if (now.getHours() < 18) {
      greeting = "Good day";
    }
    else {
      greeting = "Good evening";
    }
    return greeting;
  }
%>
<html>
  <head>
    <title>All Scripting Elements</title>
  </head>
  <body bgcolor="white">
    <%= getGreeting() %>
    <% if (request.getParameter("name") == null) { %>
      stranger!
    <% } else { %>
      partner!
    <% } %>
    How are you?
  </body>
</html>








23.29.Scriptlet
23.29.1.Scriptlet Example
23.29.2.Call function in jsp page
23.29.3.Count to 10 Example using JSP Scriptlet
23.29.4.All Scripting Elements
23.29.5.This scriptlet checks a hidden field to see whether or not to throw an exception