June 2005
Beginner to intermediate
336 pages
6h 29m
English
The code you use in scriptlets is just straight Java. For example, take a look at this scriptlet, which uses a Java if statement:
<HTML>
<HEAD>
<TITLE>
Using Java in JSP
</TITLE>
</HEAD>
<BODY>
<H1>Using Java in JSP</H1>
<%
int temperature = 72;
if (temperature < 90 && temperature > 60) {
out.println("Time for a picnic!");
}
%>
</BODY>
</HTML>
This scriptlet should send the text “Time for a picnic!” back to the browser. To check that out, enter it into a new JSP, ch05_02.jsp, and store it as webapps\chat\ch05_02.jsp. Then navigate to the URL http://localhost:8080/chat/ch05_02.jsp. As you see in Figure 5.4, this JSP does just what you'd expect.
There are some restrictions ...
Read now
Unlock full access