Java Reference
In-Depth Information
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 the scriptlets can be "interrupted", to add static content or expressions
inside them. In our example, there is both a conditional 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
conditional and the loop.
At this point, we are ready to test the new page, one very nice feature of NetBeans is
that it deploys our code in the background automatically as we work, therefore there
is no need to redeploy our application, it should be now "ready to go" without any
action on our part. After we enter some data in the input page and hit submit , we
should see the output page rendered in the browser.
Assuming the user entered David Heffelfinger as the full name and selected Java and
Groovy from the checkboxes, the following data should be displayed on the screen:
We have now completed a simple but complete application using JSPs.
 
Search WWH ::




Custom Search