Class 2 Intermediate Java 30-IT-397  

Example

<%@page contentType="text/html"%>
<html>
<head><title>JSP Page</title></head>
<body>

<%@ page import="java.util.*" %>
<%-- <jsp:useBean id="beanInstanceName" scope="session" class="package.class" /> --%>
<%-- <jsp:getProperty name="beanInstanceName"  property="propertyName" /> --%>

<%--
Day.jsp
This generates a welcome message depeding upon the hour of the day.
Demonstrates the use of conditionals mixed with HTML

Brandan Jones
http://oz.uc.edu/~jonesbr
jonesbr@email.uc.edu
December 20, 2001

--%>

<%! private int hour = 0;  %>

Welcome to my page.  <BR>
<%
    // Get an instance of the calendar object so that we can find the current hour.
    Calendar cal = Calendar.getInstance();
    hour = cal.get(Calendar.HOUR_OF_DAY);
    // if tests to print a message based on the hour of the day.
    if (hour < 5) { %>
Get to bed!
<%   } else if (hour < 12) { %>
Good Morning!
<% } else if (hour < 17) { %>
Good Afternoon!
<% } else { %>
Good Evening!
<% } %>

</body>
</html>
 
 

 Predefined Variables

Created by:  Brandan Jones December 17, 2001