|
General Tags:
One of the most common functions used in a JSP page is
displaying the values. This can be accomplished by the tag
<c:out value="The Bean value is ${bean.attribute}" default=" actual value is null" />
You can also specify a default value which will be displayed
if the attribute is null.
What would you do when you want to set the user Id into session
scope or modify some value that is in request scope or
application scope in a JSP page? One option is to manipulate the
application scoped variable in the actionHandler layer and pass
it on to the JSP page by setting the value in the page bean.
That is surely an elegant way of doing it but just think of all
the trouble if this has to be done for say just one JSP page
with one field. The c:set tag can help set and get any scoped
values for a JSP page without the hassle of a page bean. The
variables can be in page, session, application or request scope.
<c:set value="some Value" var="scopeVarName" scope="request" />
If the value in the above statement is set to null then the
scoped variable specified in "var" is removed from the specified
scope. The set tag also provides a facility to manipulate a
collection or a bean that is in scope.
<c:set value="someValue" target="targetColl" property="keyinColl" />
This could be a request collection or a session collection. The
target collection is specified in the target attribute and the
field or key to be modified is defined in the property
attribute. If the target is a collection (map) then the key
that matches the one in the property is retrieved. The retrieved
key is used to update the value corresponding to the key in the
map. If no key matches the property in the target collection
then a new key value pair is created in the collection. If the
target is not a Map then it is assumed to be a JavaBean and the
c:set follows the general rules for getting and setting values
in a JavaBean.
Another common functionality required on a JSP page is exception
handling. I used to always get annoyed with the Jasper Runtime
exception that is thrown on the JSP page. The exception was
annoying as it displays a detailed and mostly useless stack
trace for the simplest of errors. The best solution to this
problem is to define an error page in the JSP, but the error
page is very generic and would be good for critical errors that
occur on a page. However for simpler errors like user defined
exceptions and missing values, handling the error on the page
would give more flexibility to the developer. This is equivalent
to enclosing the whole JSP with a try and catch block except
that this is a more elegant way of doing it.
<c:catch var="varName">
Exception Code
.
</c:catch>
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|