Java Reference
In-Depth Information
If you tried to do something like this inside of a scriptlet, you would get
errors when the server tries to compile your JSP. Such syntax belongs at the
outer lexical level. The use of the <%! ... %> syntax puts it there.
19.3.3
This delimiter is a shorthand for getting output from a very small bit of Java
into the output stream. It's not a complete Java statement, only an expression
that evaluates into a String . Here's an example:
Expression
<h4>As of <%= new java.util.Date() %></h4>
which will create a Java Date object (initialized, by default, with the current
date/time) and then call the toString() method on that object. This yields a
date/time stamp as part of an <h4> heading.
Any methods and variables defined inside the previously described
delimiters are OK to use with this expression shorthand.
There are also a few predefined servlet variables.
We've described how the JSP is converted into a servlet—the HTML
statements become println() calls. This all happens inside of an
HttpServlet -like class, just like our BudgetProServlet extends
HttpServlet in the previous chapter. In such a class, the method called when
a request arrives from a browser looks very much like our doBoth() method:
doBoth(HttpServletRequest request, HttpServletResponse response)
TIP
If you want to see the source for the servlet that gets generated when a JSP is
converted, and if you're using NetBeans, right-click on the filename (in the
Explorer view) and, from this menu, choose Compile . Then do it again and
you'll notice that the second choice on the menu is View Servlet (Figure 19.1).
If you are using Apache Tomcat as your Web server, just look in the work
subdirectory in the directory where Tomcat is installed. In the appropriate subdi-
rectory you will find both the .java and .class files for your converted JSP
with the .jsp suffix converted to $jsp.java and $jsp.class respectively.
For example, BPAcct.jsp becomes BPAcct$jsp.java and is compiled
into BPAcct$jsp.class .
Search WWH ::




Custom Search