13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

430Chapter 19JSP: Servlets Turned Inside OutIf you tried to do something like this inside of a scriptlet, you would geterrors when the server tries to compile your JSP. Such syntax bel<strong>on</strong>gs at theouter lexical level. The use of the syntax puts it there.19.3.3 Expressi<strong>on</strong>This delimiter is a shorthand for getting output from a very small bit of Javainto the output stream. It’s not a complete Java statement, <strong>on</strong>ly an expressi<strong>on</strong>that evaluates into a String. Here’s an example:As of which will create a Java Date object (initialized, by default, with the currentdate/time) and then call the toString() method <strong>on</strong> that object. This yields adate/time stamp as part of an heading.Any methods and variables defined inside the previously describeddelimiters are OK to use with this expressi<strong>on</strong> shorthand.There are also a few predefined servlet variables.We’ve described how the JSP is c<strong>on</strong>verted into a servlet—the HTMLstatements become println() calls. This all happens inside of anHttpServlet-like class, just like our BudgetProServlet extendsHttpServlet in the previous chapter. In such a class, the method called whena request arrives from a browser looks very much like our doBoth() method:doBoth(HttpServletRequest request, HttpServletResp<strong>on</strong>se resp<strong>on</strong>se)TIPIf you want to see the source for the servlet that gets generated when a JSP isc<strong>on</strong>verted, and if you’re using NetBeans, right-click <strong>on</strong> the filename (in theExplorer view) and, from this menu, choose Compile. Then do it again andyou’ll notice that the sec<strong>on</strong>d choice <strong>on</strong> the menu is View Servlet (Figure 19.1).If you are using Apache Tomcat as your Web server, just look in the worksubdirectory in the directory where Tomcat is installed. In the appropriate subdirectoryyou will find both the .java and .class files for your c<strong>on</strong>verted JSPwith the .jsp suffix c<strong>on</strong>verted to $jsp.java and $jsp.class respectively.For example, BPAcct.jsp becomes BPAcct$jsp.java and is compiledinto BPAcct$jsp.class.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!