Thursday, February 7, 2013

Head First Servlets and JSP: Chapter 9 Scriptless using JSTL (Java Standard Tag Library)

we will talk here about using the Tagging library,

c:out example:

imagine you want to output <b></b> as text, you should write

or you can write a function for that and start using it



however with the tag library you can write



c:foreach example:






c:if example:




c:choose example




c:set example:




c:remove example:




c:url example
you use c:url to encode the url so the sessionid will be added


Define an error Page
1- add a jsp file (e.g. errorPage.jsp) and add the follwoing:

2- now in any page you can reference this error page.



3- you can also apply this to all pages by adding this to the web.xml

this will catch all exceptions

you can also write:


c:catch


How to Understand a TLD file
when you get an TLD file from someone you should understand the follwoing things:



as you can see you have URI, tagName and Tag attriutes

as you can see also, we have <tag-class> which is the class that does all the job, in this case the class is foo.AdvisorTaghandler

and the class will be like this:



No comments:

Post a Comment