Developing Web Applications With Ant by Richard Hightower - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

HelloWorld.jsp

HelloWorld.jsp exists to display the message it gets from the Greeting reference that HelloWorldServlet mapped into that session. The HelloWorld.jsp code looks like this:

<jsp:useBean id="greeting" type="xptoolkit.model.Greeting"
scope="session"/>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1><%=greeting.getGreeting()%></h1>
</body>

If you are a Web designer at heart, we understand if you are shocked and horrified by this HTML code. But for a moment, let's focus on the following two lines of code from the JSP:

 

<jsp:useBean id="greeting" type="xptoolkit.model.Greeting"
scope="session"/>
<h1><%=greeting.getGreeting()%></h1>

Notice that the jsp:useBean action grabs the Greeting reference that we put into the session with HelloWorldServlet. Then, we print out the greeting with the JSP scriptlet expression <%=greeting.getGreeting()%>.

This sums up what the Model 2 Hello World Web application does. We discuss the other JSP, HelloApplet.jsp, after we examine the applet subproject. For now, the next section explains why the servlet could forward HelloWorldJSP to the JSP HelloWorld.jsp.