Java Reference
In-Depth Information
@DefaultHandler
Ì
public Resolution currentDate() {
date = new Date();
return new ForwardResolution(VIEW);
}
public Resolution randomDate() {
long max = System.currentTimeMillis();
long random = new Random().nextLong() % max;
date = new Date(random);
return new ForwardResolution(VIEW);
}
private static final String VIEW = "/WEB-INF/jsp/hello.jsp";
}
The class implements the ActionBean interface ( Ê ) with a standard get-
ter and setter. Next, the date property is defined at Ë . The JSP will
access this property using the Expression Language (EL) to display the
date. Finally, the currentDate ( ) event handler ( Ì ) refreshes the current
date, while randomDate ( ) produces a random date. Both event handlers
set the date property and then forward to /WEB-INF/jsp/hello.jsp using a
ForwardResolution . The next step is to create the hello.jsp file.
Writing the JSP
The hello.jsp file is responsible for displaying the page that we see in Fig-
ure 2.2 , on page 27 . Most of it is plain HTML, but there two interesting
parts: displaying the date and time and creating links that trigger event
handlers on the action bean.
Let's look at the source for hello.jsp :
Download getting_started/web/WEB-INF/jsp/hello.jsp
<%@page contentType="text/html;charset=ISO-8859-1" language="java"%>
<%@taglib prefix="s" uri="http://stripes.sourceforge.net/stripes.tld"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title> Hello, Stripes! </title>
</head>
<body>
<h3> Hello, Stripes! </h3>
<p>
Date and time:
<br>
 
 
Search WWH ::




Custom Search