Java Reference
In-Depth Information
The replaceText() method in lines 11-21 of Listing 21.11 does most of the work in the
class. It takes three arguments:
A string that might contain unwanted characters
n
A character that should be removed
n
A character that should be added in its place
n
When you compile the Guestbook class, it should be stored in a WEB-INF\classes\
example subfolder in the same part of the webapps hierarchy as the project's JSP page.
For example, if the pages are in webapps\jspexamples\jsp , the class file should be
saved in webapps\jspexamples\WEB-INF\classes\example .
To test the guestbook-post.jsp page, open the page that displays guestbook entries
using an ID parameter of cinema again, as in this example:
http://localhost:8080/java/guestbook.jsp?id=cinema
Add a few guestbook entries to see how they are displayed in the guestbook.
JSP Standard Tag Library
For Java programmers eager to apply their skills on the Web, the development of the lan-
guage for server-side programming has been one of those “walk before you can crawl”
situations.
When servlets were introduced, they made it possible to use Java to create programs sim-
ilar to CGI scripts that collect input from web forms and URL parameters, producing
HTML output in response. This works great for writing programs to process mail and
handle other simple tasks, but as larger web applications require multiple pages, it
becomes clear that producing HTML output using Java statements can be cumbersome.
Revisions become more difficult, especially for any nonprogrammers involved in the
work.
Two years later, Sun took another step in the right direction with JSP, which make it easy
to combine static HTML output with dynamic output created by Java statements. Using
JSP, Java code can be placed on web pages among HTML markup and edited like any
other page. Programmers also can create their own custom JSP markup tags to interact
with Java objects. The pages compile into servlets automatically.
21
Unfortunately, the ease with which Java code could be placed on a JSP page proved to be
a misstep because it encourages the bad habit of placing a lot of mission-critical applica-
tion code in a place where it's hard to maintain, is not secure, and is easily bungled by
 
Search WWH ::




Custom Search