Upload
alok-chandna
View
212
Download
0
Tags:
Embed Size (px)
Citation preview
1. Installing JSTL : a. JSTL is not part of JSP 2.0 specb. Having access to Servlet and JSP API’s does not mean u have access to JSTLc. Put jstl.jar and standard.jar in WEB-INF/lib
2. Standard library of custom tags : JSP Standard Tag Library3. If you need more you can create a custom tag library developed for ur own company4. U wud learn how to use core jstl tags as well as custom tags from other libraries
1. Even if u don’t mention escapeXml then by default special characters are converted to entity code using <c:out, so that they can be displayed as it is
2. Setting a default value with <c:out
But we don’t want “space”
So
Looping without scripting
1. Collection here means either an array or Collection or Map or comma delimited string
2. Getting loop counter
3.
4. Using c: as prefix is a convention , u can give other prefix but u must give one5. The var variable is scoped only to the tag
6.
7.
So what do we do
8. <c:set>With <jsp:setProperty> u can just set the property oif beans
But with <c:set> you can set request attributes, map values,new entry in map
<c:set> comes in 2 flavours
1. Var2. Target
Each of the 2 flavors have 2 versions with and without body
<c:remove>
487 onwards from book
1. Session tracking happens automatically with JSP’s unless you disable with a page directive that has an attribute that says session=”false”.
2. If the client does not support cookies however, then use <c:url> in JSP they provide URL rewriting
What if URL needs encoding
1. If unsafe/reserved characters like “space”are appended in query string they can create problems but with encoding they are encoded.eg a space is replaced with a + sign
Error pages
1. U can declare error pages in DD for entire web app2. U can even configure error pages for different exceptions types or HTTP error
codes(404,500,etc)3. The container uses<error-page> configuration in DD as default but if a JSP has an explicit error
page directive , the container uses the directive
1. In a scriptlet u can use the implicit object exception2. From JSP u use the EL implicit object ${pageContext.exception}3. The object is of type java.lang.Throwable4. So in script u can call methods and in EL u can access stackTrace and message properties
1. <c:catch> serves as both try and catch there’s no separate try tag2. u wrap risky EL or tag calls or whatever in the body of a <c:catch> and the exception is caught
right there3. nothing runs in the <c:catch> body once an exception occurs4. so it is like try in java
Now since we have not moved to error page we don’t have access to exception object
So what do we do?
JSTL has 5 libraries : 4 with custom tags and one with a bunch of functions for String manipulation
Using a tag library that’s not from JSTL
1. with JSTL docs u knowhow to use JSTL custom tags but how do u use a custom tag library created for your company
2. how do u deploy it
Things u have to know
1. the tag name and syntaxa. tag name comes from TLD : in <c:set>, tag name is set and prefix can be anythingb. syntax tells required and optional attributes, if tag can have body, if so what to put
there,c. type of attribute and if the attribute can be expression
2. the library URIa. URI is unique identifier in TLDb. Its what u put in ur taglib directivec. Used to map tag to java code
1. This simple tag handler extends SimpleTagSupport2. Implements 2 key methods
a. doTag() : does the actual workb. setUser() : accepts the attribute value