Java Reference
In-Depth Information
This feature can be used both as a learning tool so that we can see what functionality
is available, and as a reference for more experienced developers.
In addition to JSP expressions, our page contains JSP scriptlets. Scriptlets can contain
any arbitrary Java code and have access to all implicit objects. In our example, the
first scriptlet obtains the values of the request parameter named progLang ; this is the
name we used on the input JSP for all checkboxes. Using the same name for several
checkboxes has the effect of creating a request parameter whose value is an array of
String objects containing the values of the checkboxes that were checked. Our JSP
obtains this array and assigns it to a variable named selectedLanguages ; it then
iterates through this array and outputs the value to the page as an unordered list
(bullet points).
Notice that scriptlets can be "interrupted", to add static content or expressions
inside them. In our example, there is both a condition and a loop started in the first
scriptlet, then there is some static markup to generate an item in the list and an
expression to display the current element in the list. The next scriptlet closes both the
condition and the loop.
At this point, we are ready to test the new page. We should redeploy our application
by right-clicking on it in the project window and selecting Run . At this point the
input page should show up automatically on the browser. Assuming the user
entered "David Heffelinger" as the full name and selected "Java" and "Perl" from
the checkboxes, then submitted the form by clicking on the Submit button, our new
page should be displayed on the screen.
We have now completed a simple but complete application using JSPs.
 
Search WWH ::




Custom Search