<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Remember the code? &#187; SCWCD</title>
	<atom:link href="http://code.neox.net/tag/scwcd/feed/" rel="self" type="application/rss+xml" />
	<link>http://code.neox.net</link>
	<description>a place where I store my secret powerful coding snippets, or just to remember how to do things</description>
	<lastBuildDate>Fri, 19 Jun 2009 11:36:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SCWCD certification passed</title>
		<link>http://code.neox.net/2008/05/12/scwcd-certification-passed/</link>
		<comments>http://code.neox.net/2008/05/12/scwcd-certification-passed/#comments</comments>
		<pubDate>Tue, 13 May 2008 00:01:55 +0000</pubDate>
		<dc:creator>HanaDaddy</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[SCWCD]]></category>

		<guid isPermaLink="false">http://code.neox.net/?p=26</guid>
		<description><![CDATA[Finally after about a month of certification preparation, I took the test today.
But I was lost while getting to the test site.
So here is my lesson , be fully prepared  
And I did pass the test with the average score.
By the way the passing grade is 70.
Good Luck if you plan to take the [...]]]></description>
			<content:encoded><![CDATA[<p>Finally after about a month of certification preparation, I took the test today.</p>
<p>But I was lost while getting to the test site.</p>
<p>So here is my lesson , be fully prepared <img src='http://code.neox.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>And I did pass the test with the average score.</p>
<p>By the way the passing grade is 70.</p>
<p>Good Luck if you plan to take the test. Try to solve mock exams as many as possible. They do help.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.neox.net/2008/05/12/scwcd-certification-passed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[SCWCD] Cram Sheet 9 &#8211; Filters and Design Patterns</title>
		<link>http://code.neox.net/2008/05/06/scwcd-cram-sheet-9-filters-and-design-patterns/</link>
		<comments>http://code.neox.net/2008/05/06/scwcd-cram-sheet-9-filters-and-design-patterns/#comments</comments>
		<pubDate>Wed, 07 May 2008 02:16:25 +0000</pubDate>
		<dc:creator>HanaDaddy</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[SCWCD]]></category>

		<guid isPermaLink="false">http://code.neox.net/?p=25</guid>
		<description><![CDATA[Chapter 13 Filters and wrappers
Filters can intercept request before servlet and/or process reponse after servlet is completed.
Filters can be chained with other filters.
You must implement all methods  : init() , doFilter() , destroy().

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import javax.servlet.* ; // Filter and FilterChain are located here
public class BeerRequestFilter implements Filter &#123;
	private FilterConfig fc;
&#160;
	//You must implement init &#38; destroy [...]]]></description>
			<content:encoded><![CDATA[<h2>Chapter 13 Filters and wrappers</h2>
<p>Filters can intercept request before servlet and/or process reponse after servlet is completed.<br />
Filters can be chained with other filters.<br />
You must implement all methods  : <code>init() , doFilter() , destroy()</code>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="java"><span style="color: #a1a100;">import javax.servlet.* ; // Filter and FilterChain are located here</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BeerRequestFilter <span style="color: #000000; font-weight: bold;">implements</span> Filter <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> FilterConfig fc<span style="color: #66cc66;">;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">//You must implement init &amp; destroy methods</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> init <span style="color: #66cc66;">&#40;</span>FilterConfig config<span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException <span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">fc</span>=config<span style="color: #66cc66;">;</span>
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #808080; font-style: italic;">// doFilter args are not HttpServletRequest and HttpServletResponse.</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> doFilter<span style="color: #66cc66;">&#40;</span>ServletRequest req, ServletResponse resp, FilterChain chain<span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span>
			ServletException, <span style="color: #aaaadd; font-weight: bold;">IOException</span> <span style="color: #66cc66;">&#123;</span>
		HttpServletRequest httpReq = <span style="color: #66cc66;">&#40;</span>HttpServletRequest<span style="color: #66cc66;">&#41;</span> req<span style="color: #66cc66;">;</span> 
		<span style="color: #808080; font-style: italic;">// This casting is possible because the req is in fact HttpServletRequest!</span>
&nbsp;
		<span style="color: #aaaadd; font-weight: bold;">String</span> name = httpReq.<span style="color: #006600;">getRemoteUser</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>name <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			fc.<span style="color: #006600;">getServletContext</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">log</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;User &quot;</span> + name + <span style="color: #ff0000;">&quot; is updating&quot;</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
		<span style="color: #66cc66;">&#125;</span>
		chain.<span style="color: #006600;">doFilter</span><span style="color: #66cc66;">&#40;</span>req.<span style="color: #006600;">resp</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;">//calling next filter</span>
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #808080; font-style: italic;">//You are required to implement destroy()</span>
	<span style="color: #000000; font-weight: bold;">Public</span> <span style="color: #993333;">void</span> destroy<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p><span id="more-25"></span><br />
DD</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;filter<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;filter-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>BeerRequest<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/filter-name<span style="font-weight: bold; color: black;">&gt;</span></span></span> <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- mandatory --&gt;</span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;filter-class<span style="font-weight: bold; color: black;">&gt;</span></span></span>com.examle.BeerRequestFilter<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/filter-class<span style="font-weight: bold; color: black;">&gt;</span></span></span> <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- mandatory --&gt;</span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;init-param<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;param-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>LogFileName<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/param-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;param-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>UserLog.txt<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/param-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/init-param<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/filter<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p>*Two ways to define filter-mapping : with <code>&lt;servlet-name&gt; or &lt;url-pattern&gt;</code><br />
<strong>Declare filter mapping with a URL pattern</strong></p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;filter-mapping<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;filter-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>BeerRequest<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/filter-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;url-pattern<span style="font-weight: bold; color: black;">&gt;</span></span></span>*.do<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/url-pattern<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/filter-mapping<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p>Declare filter mapping to a servlet name</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;filter-mapping<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;filter-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>BeerRequest<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/filter-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;servlet-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>AdviceServlet<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/servlet-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/filter-mapping<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p>* One filter mapped multiple resources: Matching <code>&lt;url-pattern&gt;</code> processed first then Matching <code>&lt;servlet-name&gt;</code> are processed.  Then in the order of they are list up in the DD.</p>
<p>*Dispatcher element is to define which action this filter is responsible to listen.</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;filter-mapping<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;filter-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>BeerRequest<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/filter-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;url-pattern<span style="font-weight: bold; color: black;">&gt;</span></span></span>*.do<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/url-pattern<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;dispatcher<span style="font-weight: bold; color: black;">&gt;</span></span></span>REQUEST<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/dispatcher<span style="font-weight: bold; color: black;">&gt;</span></span></span>  
	'dispatcher' can be used 0 ~ 4 time. Default is REQUEST
		And/or
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;dispatcher<span style="font-weight: bold; color: black;">&gt;</span></span></span>INCLUDE<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/dispatcher<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		And/or
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;dispatcher<span style="font-weight: bold; color: black;">&gt;</span></span></span>FORWARD<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/dispatcher<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		And/or
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;dispatcher<span style="font-weight: bold; color: black;">&gt;</span></span></span>ERROR<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/dispatcher<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/filter-mapping<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p><strong>(*) Filter for reponse</strong></p>
<p>For the same Filter class, define post activities after the <code>chain.doFilter(req,resp);</code> and they will be run after servlet is finished.</p>
<p>However, the response is already commited by servlet.  You will need to create a new HttpServletReponse implemented class. Make this to use customs output stream and pass it down to servlet in chain.doFilter.</p>
<p>But creating a custom reponse class directly from the HttpServletResponse interface. So we extend wrapper classes.</p>
<p>Wrapper class wraps the real request or response and delegates call to the real thing(HttpServletResponse or HttpServletRequest)</p>
<ul>
<li>ServletRequestWrapper</li>
<li>HttpServletRequestWrapper</li>
<li>ServletResponseWrapper</li>
<li>HttpServletResponseWrapper</li>
</ul>
<p>Wrapper is usually called as &#8220;Decorate Pattern&#8221;</p>
<h2>Chapter 14 Enterprise Design Patterns</h2>
<p>A software design pattern is a &#8220;repeatable solution for a commonly-occuring software problem&#8221;.</p>
<p>Characteristics explained before we go into patterns</p>
<ul>
<li>Code to interface : polymorphism</li>
<li>Separation of concern &#038; cohesion : separating concerns ==> increased cohesion</li>
<li>Hide Complexity</li>
<li>Loose Coupling : less two classes know each other . coding to interfaces</li>
<li>Remote Proxy : an object local to the &#8220;client&#8221; object that pretends to be a remote object.</li>
<li>Increase Declarative Control : using DD instead of hard coding</li>
</ul>
<p>* J2EE pattern for Remote model Components : What to do when Models are remote?<br />
- <strong>JNDI</strong>: Java Naming &#038; Directory Interface => gives a network a centralized location to find things.<br />
- <strong>RMI</strong>; Remote Method Invocation => pretend that you&#8217;re invoking local object . Local stub act as proxy &#8216; server skeleton object similar to stub handle the request.</p>
<ol>
<li>Create a remote interface &#8211; both STUB (proxy) and remote actual Model service will implement this interface</li>
<li>Create Actual model with the interface. This includes code that registers the model with a well-known registry such as JNDI &#038; RMI registry</li>
<li>Generate Stub &#038; Skeleton object. RMI compiler rmic (command) create proxies</li>
<li>Start Model Service (register itself and wait for calls)</li>
</ol>
<p><strong>* Business Delegate</strong><br />
Connect Service Module (JNDI) and talk to the stub for the business methods.</p>
<p><strong>*Service Locator</strong> : JNDI access module.</p>
<p><strong>*Transfer Object</strong>: JSP can use stub object using EL, but it will make a network call each time( Expensive) So, we bring the actual Model object to local. However the trade off is that the data is not up-to-date (stale) </p>
<p><strong>*Front Controller</strong> : a single component , usually a servlet but possibly JSP act as the single control point for the presentation tier of a web application.</p>
<p><strong>(*) Summary</strong></p>
<p><strong>*Business Delegate </strong>: Act as proxy. Handles communication details &#038; Errors</p>
<ul>
<li>Hiding complexity</li>
<li>Coding to interface</li>
<li>Loose coupling</li>
<li>Sepratino of concerns</li>
</ul>
<p><strong>*Service Locator : </strong><br />
- obtains InitialContext Objects<br />
- performs registry lookups (JNDI, RMI, UDDI,COS)<br />
- handles communication details &#038; exceptions<br />
- can cache result for better performance</p>
<ul>
<li>Hiding complexity</li>
<li>Separation of Concerns</li>
</ul>
<p><strong>*Transfer Object</strong><br />
- provides a local representation of a remote entity<br />
- the data is stale</p>
<ul>
<li>Reduce network traffic</li>
</ul>
<p><strong>*Intercepting Filter</strong>:<br />
- can intercept &#038; modify request before servlet<br />
- can intercept &#038; modify response after servlet<br />
- deployed using DD<br />
- executed in chains<br />
- must implement container call back methods (init,doFilter,destroy)</p>
<ul>
<li>Cohesion
<li>Loose coupling
<li>Increasing declarative control
</ul>
<p><strong>*MVC</strong></p>
<ul>
<li>Separation of concerns</li>
<li>Loose coupling</li>
</ul>
<p><strong>*Front Controller</strong></p>
<ul>
<li>Hiding complexity</li>
<li>Separation of concerns</li>
<li>Loose coupling</li>
</ul>
<p>And this is finally the end. </p>
<p>Hope you had some fun reviewing the cram sheets and Good luck with your certification test!</p>
]]></content:encoded>
			<wfw:commentRss>http://code.neox.net/2008/05/06/scwcd-cram-sheet-9-filters-and-design-patterns/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[SCWCD] Cram Sheet 8 &#8211; Web Deployment and Security</title>
		<link>http://code.neox.net/2008/05/01/scwcd-cram-sheet-8-web-deployment-and-security/</link>
		<comments>http://code.neox.net/2008/05/01/scwcd-cram-sheet-8-web-deployment-and-security/#comments</comments>
		<pubDate>Fri, 02 May 2008 02:41:09 +0000</pubDate>
		<dc:creator>HanaDaddy</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[SCWCD]]></category>

		<guid isPermaLink="false">http://code.neox.net/?p=24</guid>
		<description><![CDATA[Chapter 11 Web Deployment
Web App Folder Structure



/myApp (.jsp , .html ) ==>
  

/WEB-INF ==>
  

/lib ( jar files)
/classes (class files)
/tags ( tag files)
(TLD files)
  


*WAR file (Web Archive) &#8211; This is in fact jar file and contains all application files including WEB-INF.
One thing special is WAR has /META-INF/MANIFEST.MF gives you deploy time [...]]]></description>
			<content:encoded><![CDATA[<h2>Chapter 11 Web Deployment</h2>
<p>Web App Folder Structure</p>
<table>
<tr>
<td valign="top">
/myApp (.jsp , .html ) ==>
  </td>
<td valign="top">
/WEB-INF ==>
  </td>
<td valign="top">
/lib ( jar files)<br />
/classes (class files)<br />
/tags ( tag files)<br />
(TLD files)
  </td>
</tr>
</table>
<p>*WAR file (Web Archive) &#8211; This is in fact jar file and contains all application files including WEB-INF.<br />
One thing special is WAR has <strong><code>/META-INF/MANIFEST.MF</code></strong> gives you deploy time check for classes &#038; packages that WAR depends on.</p>
<p>*Direct access to files under WEB-INF and META-INF will show 404 error.</p>
<p>* <code>&lt;servet&gt;&lt;url-pattern&gt;</code> matching order</p>
<ol>
<li>Exact match : /Beer/SelectBeear.do</li>
<li>Directory match : /Beer/* </li>
<li>Extension match : *.do </li>
</ol>
<p>The most specific match always win.</p>
<p>*Welcome files</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;welcome-file-list<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;welcome-file<span style="font-weight: bold; color: black;">&gt;</span></span></span>index.html<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/welcome-file<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;welcome-file<span style="font-weight: bold; color: black;">&gt;</span></span></span>default.jsp<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/welcome-file<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/welcome-file-list<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p><span id="more-24"></span><br />
*Error page</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;error-page<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;exception-type<span style="font-weight: bold; color: black;">&gt;</span></span></span>java.lang.Throwable<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/exception<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;location<span style="font-weight: bold; color: black;">&gt;</span></span></span>/errorpage.jsp<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/location<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/error-page<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;error-page<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;exception-code<span style="font-weight: bold; color: black;">&gt;</span></span></span>404<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/exception<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;location<span style="font-weight: bold; color: black;">&gt;</span></span></span>/notFound.jsp<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/location<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/error-page<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p>*<code>response.sendError(403);</code>// sendError cause error programmatically</p>
<p>*If you want to load servlet at the deploy time (server start &#038; start)</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;servlet<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;servlet-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>Servlet1<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/servlet-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;servlet-class<span style="font-weight: bold; color: black;">&gt;</span></span></span>com.example.Servlet1<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/servlet-class<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;load-on-startup<span style="font-weight: bold; color: black;">&gt;</span></span></span>1<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/load-on-startup<span style="font-weight: bold; color: black;">&gt;</span></span></span> <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- note here --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/servlet<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p><code>&lt;load-on-startup&gt;</code>: Bigger than zero will load servlet at startup. This  value determines the order of preloading if defined with multiple servlets.</p>
<p>* XML JSP Syntax</p>
<table border="1" >
<tr>
<th>Normal JSp</th>
<th>Jsp document syntax</th>
</tr>
<tr>
<td><code>&lt;%@ page import="java.util.*" %&gt;</code></td>
<td><code>&lt;jsp:directive.page import="java.util.*" %&gt;</code></td>
</tr>
<tr>
<td><code>&lt;%! Int y=3; %&gt;</code></td>
<td><code>&lt;jsp:declaration&gt;int y=3;&lt;/jsp:declaration&gt;</code></td>
</tr>
<tr>
<td><code>&lt;% list.add("Fred"); %&gt;</code></td>
<td><code>&lt;jsp:scriptlet&gt;list.add("Fred");&lt;/jsp:scriptlet&gt;</code></td>
</tr>
<tr>
<td><code>Text</code></td>
<td><code>&lt;jsp:text>Text&lt;/jsp:text&gt;</code></td>
</tr>
<tr>
<td><code>&lt;%= it.next() %&gt;</code></td>
<td><code>&lt;jsp:expression>it.next()&lt;/jsp:expression&gt;</code></td>
</tr>
</table>
<p>* EJB DD tag<br />
-Reference to local bean</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ejb-local-ref<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ejb-ref-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>ejb/Customer<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ejb-ref-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ejb-ref-type<span style="font-weight: bold; color: black;">&gt;</span></span></span>Entity<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ejb-ref-type<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;local-home<span style="font-weight: bold; color: black;">&gt;</span></span></span>com.test.TestHome<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/local-home<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;local<span style="font-weight: bold; color: black;">&gt;</span></span></span>com.test.Test<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/local<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ejb-local-ref<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p>-Refernce to remote bean</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ejb-ref<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ejb-ref-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>ejb/LocalCustomer<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ejb-ref-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ejb-ref-type<span style="font-weight: bold; color: black;">&gt;</span></span></span>Entity<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ejb-ref-type<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;home<span style="font-weight: bold; color: black;">&gt;</span></span></span>com.test.TestHome<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/home<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;remote<span style="font-weight: bold; color: black;">&gt;</span></span></span>com.test.Test<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/remote<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/ejb-ref<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p>Remote ejb created first and local ref created later. (that is why naming convention is inconsistent)</p>
<p>*JNDI DD tag</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;env-entry<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;env-entry-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>rates/discountRate<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/env-entry-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;env-entry-type<span style="font-weight: bold; color: black;">&gt;</span></span></span>java.lang.Integer<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/env-entry-type<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	    <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!--any type takes Sting as constructor parameter--&gt;</span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;env-entry-value<span style="font-weight: bold; color: black;">&gt;</span></span></span>10<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/env-entry-value<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	    <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Will be passed as a string (or char if entry-type is Character) --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/env-entry<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p><strong>*Declaring a <code>&lt;mime-mapping&gt;</code></strong></p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;mime-mapping<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;extension<span style="font-weight: bold; color: black;">&gt;</span></span></span>mpg<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/extension<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;mime-type<span style="font-weight: bold; color: black;">&gt;</span></span></span>video/mpeg<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/mime-type<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/mime-mapping<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<h2>Chapter 12 web app security</h2>
<ul>
<li>Authentication: userid/passwd
<li>Authorization : role
<li>Confidentiality : SSL (nobody else is able to see the data along the way)
<li>Data integrity : SSL (client gets to see what was sent by server)
</ul>
<p>DD entries</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;login-config<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;auth-method<span style="font-weight: bold; color: black;">&gt;</span></span></span>BASIC<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/auth-method<span style="font-weight: bold; color: black;">&gt;</span></span></span> <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- BASIC, DIGEST,CLIENT-CERT,FORM --&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/login-config<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;security-role<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;role-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>Admin<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/role-name<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/security-role<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;security-role<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;role-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>Member<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/role-name<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/security-role<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;security-role<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;role-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>manager<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/role-name<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/security-role<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;security-constraint<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  	<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Multiple web-resource-collection is allowed --&gt;</span></span>
  	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;web-resource-collection<span style="font-weight: bold; color: black;">&gt;</span></span></span> 
  		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;web-resource-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>AuthTest<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/web-resource-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;url-pattern<span style="font-weight: bold; color: black;">&gt;</span></span></span>/auth/*<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/url-pattern<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;url-pattern<span style="font-weight: bold; color: black;">&gt;</span></span></span>/check/*<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/url-pattern<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;http-method<span style="font-weight: bold; color: black;">&gt;</span></span></span>GET<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/http-method<span style="font-weight: bold; color: black;">&gt;</span></span></span> 
  		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;http-method<span style="font-weight: bold; color: black;">&gt;</span></span></span>POST<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/http-method<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- GET &amp; POST method are constrained (checked for access) . If http-method is not defined all methods are constrained --&gt;</span></span>
&nbsp;
  	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/web-resource-collection<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;auth-constraint<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;role-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>manager<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/role-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/auth-constraint<span style="font-weight: bold; color: black;">&gt;</span></span></span>	
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/security-constraint<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p><code>&lt;auth-constraint&gt;</code></p>
<ul>
<li>If <code>&lt;auth-constraint&gt;</code> exists, but no <code>&lt;role-name&gt;</code>defined (or <code>&lt;role-name /&gt;</code>) , no one is allowed. </li>
<li><code>&lt;role-name&gt;*&lt;/role-name&gt;</code> : all is allowed.</li>
<li>Role names are case sensitive</li>
<li>If <code>&lt;auth-constraint&gt;</code> does not exist : all is allowed</li>
</ul>
<p>When two different non-empty <code>&lt;auth-constraint&gt;</code> elements apply to the same constrained resource, access is granted to the union of all roles from both of the <code>&lt;auth-constraint&gt; elements.</p>
<p>* HttpServletRequest : three methods related security</p>
<ul>
<li><code>getUserPrincipal()</code> - EJB related</li>
<li><code>getRemoteUser()</code> - returns user name when user is logged in with BASIC(?)</li>
<li><code>isUserInRole("Manager")</code> - return true or false. The user must be authenticated and mapped to this role</li>
</ul>
<p>* If role name is hardcoded in the servlet, but you want to dynamically change the role , you can do it in DD (aliasing?)</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;security-role-ref<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;role-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>Manager<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/role-name<span style="font-weight: bold; color: black;">&gt;</span></span></span> <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!--this role name is hard coded in servlet--&gt;</span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;role-link<span style="font-weight: bold; color: black;">&gt;</span></span></span>Admin<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/role-link<span style="font-weight: bold; color: black;">&gt;</span></span></span> <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Actual role name in our application--&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/security-role-ref<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;security-role<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;role-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>Admin<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/role-name<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/security-role<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p><strong>(*) Authentication types</strong></p>
<ul>
<li>BASIC : base 64 week security</li>
<li>DIGEST : J2EE containers not required to implement</li>
<li>CLIENT-CERT : very secure. client need to have certificates</li>
<li>FORM : using html form but no encryption at all (should be used with SSL)</li>
</ul>
<p>*DD</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;login-config<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;auth-method<span style="font-weight: bold; color: black;">&gt;</span></span></span>FORM<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/auth-method<span style="font-weight: bold; color: black;">&gt;</span></span></span> <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- BASIC, DIGEST,CLIENT-CERT,FORM --&gt;</span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;form-login-config<span style="font-weight: bold; color: black;">&gt;</span></span></span> <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- form login only --&gt;</span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;form-login-page<span style="font-weight: bold; color: black;">&gt;</span></span></span>/loginPage.html<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/form-login-page<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;form-error-page<span style="font-weight: bold; color: black;">&gt;</span></span></span>/errorPage.html<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/form-error-page<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/form-login-config<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/login-config<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p><strong>*loginPage.html : Please remember that these form action and input names are mandatory.</strong></p>

<div class="wp_syntax"><div class="code"><pre>&lt;form method=&quot;POST&quot; action=&quot;j_security_check&quot; &gt;
	&lt;input type=&quot;text&quot; name=&quot;j_username&quot; &gt;
	&lt;input type=&quot;password&quot; name=&quot;j_password&quot; &gt;
	&lt;input type=&quot;submit&quot; value=&quot;Enter&quot;&gt;
&lt;/form&gt;</pre></div></div>

<p>Remember <strong>j_security_check, j_username, and j_password</strong></p>
<p><strong>(*) Using SSL </strong></p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;security-constraints<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;web-resource-collection<span style="font-weight: bold; color: black;">&gt;</span></span></span> … <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/web-resource-collection<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;auth-constraint<span style="font-weight: bold; color: black;">&gt;</span></span></span> …<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/auth-constraint<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;user-data-constraint<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;transport-guarantee<span style="font-weight: bold; color: black;">&gt;</span></span></span>CONFIDENTIAL<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/transport-guarantee<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/user-data-constraint<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/security-constraints<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<ul>
<li>NONE: default . No protection</li>
<li>INTEGRAL : data must not be changed along the way</li>
<li>CONFIDENTIAL: data must not be seen by anybody along the way</li>
</ul>
<p>Usually both INTEGRAL and CONFIDENTIAL types cause the container to use SSL.</p>
<p><a href='http://code.neox.net/2008/05/06/scwcd-cram-sheet-9-filters-and-design-patterns/'>(*) Next: [SCWCD] Cram Sheet 9 - Filters and Design Patterns</a></p>
]]></content:encoded>
			<wfw:commentRss>http://code.neox.net/2008/05/01/scwcd-cram-sheet-8-web-deployment-and-security/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[SCWCD] Cram Sheet 7 &#8211; Custom Tag Development</title>
		<link>http://code.neox.net/2008/04/29/scwcd-cram-sheet-7-using-jstl/</link>
		<comments>http://code.neox.net/2008/04/29/scwcd-cram-sheet-7-using-jstl/#comments</comments>
		<pubDate>Tue, 29 Apr 2008 04:20:41 +0000</pubDate>
		<dc:creator>HanaDaddy</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[SCWCD]]></category>

		<guid isPermaLink="false">http://code.neox.net/?p=23</guid>
		<description><![CDATA[Chapter 10 Custom Tag Development
(*) Tag File
Store the tag files in /WEB-INF/tags folder.
The name of the tag file will become the tag name. (Header.tag ==> Header will be the name of the tag in JSP)
JSP usage

&#60;%@taglib prefix=&#34;mytags&#34; tagdir=&#34;/WEB-INF/tags&#34; %&#62;


note that the tagdir attribute used instead of uri attribute
tagdir value is the folder where the tag [...]]]></description>
			<content:encoded><![CDATA[<h2>Chapter 10 Custom Tag Development</h2>
<p><strong>(*) Tag File</strong><br />
Store the tag files in <strong><code>/WEB-INF/tags</code></strong> folder.<br />
The name of the tag file will become the tag name. (Header.tag ==> Header will be the name of the tag in JSP)</p>
<p><strong>JSP usage</strong></p>

<div class="wp_syntax"><div class="code"><pre>&lt;%@taglib prefix=&quot;mytags&quot; tagdir=&quot;/WEB-INF/tags&quot; %&gt;</pre></div></div>

<ul>
<li>note that the tagdir attribute used instead of uri attribute</li>
<li>tagdir value is the folder where the tag files are located</li>
</ul>

<div class="wp_syntax"><div class="code"><pre>&lt;mytags:Header subtitle=&quot;Welcome&quot; /&gt;</pre></div></div>

<ul>
<li>Header was the name of the file. (Header.tag)</li>
</ul>
<p><strong>Header.tag</strong></p>

<div class="wp_syntax"><div class="code"><pre>&lt;em&gt;&lt;strong&gt;${subtitle}&lt;/strong&gt;&lt;/em&gt;</pre></div></div>

<p><span id="more-23"></span></p>
<p>* The difference from &lt;jsp:include&gt; or &lt;c:import&gt; is that they use parameter to pass down the variables and they will exist in the JSP after include is comleted. But with Tag file, the attribute variable will not be available after the call.</p>
<p>* Tag files do not require to be defined in TLD file. Instead we use new directive in the tag file to define various information</p>

<div class="wp_syntax"><div class="code"><pre>&lt;%@ attribute  name=&quot;subtitle&quot; required=&quot;true&quot; rtexprvalue=&quot;true&quot; %&gt;</pre></div></div>

<p>Since subtitle is required, if the attribute subtitle is not used within the tag used in the JSP, you will get exception.</p>
<p>*If you want to use body with the Tag File,<br />
JSP page</p>

<div class="wp_syntax"><div class="code"><pre>&lt;mytags:Header&gt;This is a body&lt;/mytags/Header&gt;</pre></div></div>

<p>Header.tag</p>

<div class="wp_syntax"><div class="code"><pre>&lt;em&gt;&lt;strong&gt;&lt;jsp:doBody/&gt;&lt;/strong&gt;&lt;/em&gt;</pre></div></div>

<p>Additional tag for TAG files</p>

<div class="wp_syntax"><div class="code"><pre>&lt;%@tag body-content=&quot;scriptless&quot; %&gt;</pre></div></div>

<p><strong>By default, the body-content is &#8220;scriptless&#8221; if tag directive not defined. In TAG FILE, scriplets are not allowed within BODY , so JSP for body-content not allowed.</strong></p>
<p>Searching for the tag files (order)</p>
<ol>
<li>/WEB-INF/tags</li>
<li>/WEB-INF/tags&#8217; subfolder</li>
<li>/META-INF/tags of Jar file in the /WEB-INF/lib</li>
<li>/META-INF/tags&#8217; subfolder of Jar file in the /WEB-INF/lib</li>
</ol>
<p>* If tag file is deployed in a Jar, there must be TLD file for the tag files. See below example for such case.</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;taglib</span> …<span style="font-weight: bold; color: black;">&gt;</span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;tlib-version<span style="font-weight: bold; color: black;">&gt;</span></span></span>1.0<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/tlib-version<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;uri<span style="font-weight: bold; color: black;">&gt;</span></span></span>myLib<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/uri<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;tag-file<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;name<span style="font-weight: bold; color: black;">&gt;</span></span></span>Header<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;path<span style="font-weight: bold; color: black;">&gt;</span></span></span>/META-INF/tags/Header.tag<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/path<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/tag-file<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/taglib<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p>* Scriptlet &#038; EL implicit objects can be used in tag file except ServletContext. Instead JspContext is used.</p>
<p><strong>(*) Tag Handlers</strong></p>
<p>Simple (new) &#038; Classic (old before 2.0)</p>
<p><strong>Simple Tag Handler</strong></p>
<ol>
<li>Write Class extends SimpleTagSupport</li>
<li>override doTag() method</li>
<li>create TLD file

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;tag<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;description<span style="font-weight: bold; color: black;">&gt;</span></span></span>Testing simple tag<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/description<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;name<span style="font-weight: bold; color: black;">&gt;</span></span></span>SimpleTest<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;tag-class<span style="font-weight: bold; color: black;">&gt;</span></span></span>com.example.tag.TestSimpleTag<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/tag-class<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;body-content<span style="font-weight: bold; color: black;">&gt;</span></span></span>empty<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/body-content<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/tag<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

</li>
<li>Deploy tag handlers TLD &#038; class in /WEB-INF/file.tld</li>
<li>Write JSP using the tag

<div class="wp_syntax"><div class="code"><pre>&lt;%@ taglib prefix=&quot;mytag&quot; uri=&quot;…&quot; %&gt;
&lt;mytag:SimpleTest /&gt;</pre></div></div>

</li>
</ol>
<p>* Processing Body example</p>

<div class="wp_syntax"><div class="code"><pre class="java"><span style="color: #000000; font-weight: bold;">Public</span> <span style="color: #993333;">void</span> doTag<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JspException, <span style="color: #aaaadd; font-weight: bold;">IOException</span> <span style="color: #66cc66;">&#123;</span>
	getJspBody<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">invoke</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">;</span> 
	<span style="color: #808080; font-style: italic;">// This will evaluate the body &amp; print output to the response output. (when arg is null)</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>* Simple Tag handler Processing steps</p>
<ol>
<li>Load Class</li>
<li>Instantiate class (no-arg constructor runs)</li>
<li>Calls setJspContext(JspContext)</li>
<li>If tag is nested, call the setParent(JspTag)</li>
<li>If tag has attributes , call attributes bean setters.</li>
<li>If Body exists &#038; <body-content> is not empty, setJspBody(JspFragment) is called</li>
<li>Call the doTag()</li>
</ol>
<p><strong>Example</strong><br />
<strong>Jsp Tag invocation</strong></p>

<div class="wp_syntax"><div class="code"><pre>&lt;table&gt;
	&lt;myTags:simple movieList=&quot;${movieCollection}&quot; &gt;
		&lt;tr&gt;&lt;td&gt;${movie.name}&lt;/td&gt;&lt;td&gt;${movie.genre}&lt;/td&gt;&lt;/tr&gt;
	&lt;/myTags:simple&gt;
&lt;/table&gt;</pre></div></div>

<p><strong>The Tag handler class</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java"><span style="color: #000000; font-weight: bold;">Public</span> <span style="color: #000000; font-weight: bold;">class</span> SimpleTagTest <span style="color: #000000; font-weight: bold;">extends</span> SimpleTagSupport <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #aaaadd; font-weight: bold;">List</span> movieList<span style="color: #66cc66;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> setMovieList<span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">List</span> movieList<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">movieList</span> = movieList<span style="color: #66cc66;">;</span>
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">Public</span> <span style="color: #993333;">void</span> doTag<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JspException, <span style="color: #aaaadd; font-weight: bold;">IOException</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #aaaadd; font-weight: bold;">Iterator</span> I = movieList.<span style="color: #006600;">iterator</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
		<span style="color: #b1b100;">While</span><span style="color: #66cc66;">&#40;</span>i.<span style="color: #006600;">hasNext</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			Movie movie = <span style="color: #66cc66;">&#40;</span>Movie<span style="color: #66cc66;">&#41;</span> i.<span style="color: #006600;">next</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
			getJspContext<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">setAttributes</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;movie&quot;</span>, movie<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
			getJspBody.<span style="color: #006600;">invoke</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><strong>The TLD</strong></p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;tag<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;description<span style="font-weight: bold; color: black;">&gt;</span></span></span>takes an attribute and iterates over body<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/description<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;name<span style="font-weight: bold; color: black;">&gt;</span></span></span>simple<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;tag-class<span style="font-weight: bold; color: black;">&gt;</span></span></span>com.example.tag.SimpleTagTest<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/tag-class<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;body-content<span style="font-weight: bold; color: black;">&gt;</span></span></span>scriptless<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/body-content<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;attribute<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;name<span style="font-weight: bold; color: black;">&gt;</span></span></span>movieList<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;required<span style="font-weight: bold; color: black;">&gt;</span></span></span>true<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/required<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;rtexprvalue<span style="font-weight: bold; color: black;">&gt;</span></span></span>true<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/rtexprvalue<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/attribute<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/tag<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p>JspFragment is an object represents JSP code (JspFragment jf = getJspBody(); )<br />
Body of tag is encapsulated in JspFragment &#038; then sent to the tag handler in the setJspBody(). <strong>No Scriptlets are allowed in body of tag for Simple Tag.</strong></p>
<p>*<code>JspFragment.invoid(java.io.writer)</code> : use null as arg to send output to response otherwise create a write object &#038; pass it. Work with write to access the body.</p>
<p>If <code>doTag()</code> throws <strong>SkipPageException</strong>, all the contents will be shown right before Exception. But the rest of the page will not be shown. (Stop processing)   If JspException occurs , error page will be shown.</p>
<p><strong><br />
<h3>(*) Classic Handler</h3>
<p></strong></p>
<p>Create a classic handler by extending TagSupport or BodyTagSupport.</p>
<p>The order that BodyTag is extended / implemented parents classes.<br />
JspTag interface <== Tag interface <== IterationTag interface (doAfterBody() belongs here ) <== BodyTag interface (doInitBody(), setBodyContent(BodyContent) belong this interface)</p>
<p>TagSupport implement IterationTag interface.<br />
BodyTagSupport implement BodyTag interface.</p>
<p><code>public int doStartTag() throws JspException </code> (Note that no IOException)</p>
<ul>
<li><strong>Return SKIP_BODY ==> No Body Process</strong></li>
<li><strong>Return EVAL_BODY_INCLUDE ==> Body process ==> call doAfterBody()</strong></li>
</ul>
<p><code>public int doEndTag() throws JspException</code></p>
<ul>
<li><strong>Return EVAL_PAGE ==> cdontinue with the rest of page</strong></li>
<li><strong>Return SKIP_PAGE ==> same as SkipPageException.</strong></li>
</ul>
<p>LifeCycle</p>
<ol>
<li>Load class</li>
<li>Instantiate class (call no-arg constructor)</li>
<li>Call setPageContext(Pagecontext)</li>
<li>If tag nested, call setParent(Tag)</li>
<li>If tag has attributes, call attributes setters</li>
<li>Call doStartTag()</li>
<li>If doStartTag returns EVAL_BODY_INCLUDE  , the body is evaluated.</li>
<li>doAfterBody() is called after body is evaluated</li>
<li>doEndTag()</li>
</ol>
<p><code>public int doAfterBody() throws JspException</code></p>
<ul>
<li><strong>Return SKIP_BODY ==> goto doEndTag()</strong></li>
<li><strong>Return EVAL_BODY_AGAIN ==> eval body again ==> doAfterBody called again</strong></li>
</ul>
<p>Default Return Values of the methods if not overridden:</p>
<ul>
<li>doStartTag ==> SKIP_BODY</li>
<li>doAfterBody ==> SKIP_BODY</li>
<li>doEndTag ==> EVAL_PAGE</li>
</ul>
<p>Classic handler object is reused unlike simple handler.</p>
<p><strong>* Dynamic Attribute Interface</strong><br />
	To pass down bunch of attributes to that are not actually used in the TAG class. Just like HTML default attributes.</p>
<p>Implement DynamicAttributes interface</p>

<div class="wp_syntax"><div class="code"><pre class="java"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> setDynamicAttribute<span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">String</span> uri,<span style="color: #aaaadd; font-weight: bold;">String</span> name, <span style="color: #aaaadd; font-weight: bold;">Object</span> value<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	hashmap.<span style="color: #006600;">put_</span><span style="color: #66cc66;">&#40;</span>name, value<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>TLD  for Dynamic Attribute</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;tag<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;name<span style="font-weight: bold; color: black;">&gt;</span></span></span>…<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/name<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;tag-class<span style="font-weight: bold; color: black;">&gt;</span></span></span>…<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/tag-class<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;body-content<span style="font-weight: bold; color: black;">&gt;</span></span></span>empty<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/body-content<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;attribute<span style="font-weight: bold; color: black;">&gt;</span></span></span> 
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;name<span style="font-weight: bold; color: black;">&gt;</span></span></span> …<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/name<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;type<span style="font-weight: bold; color: black;">&gt;</span></span></span>…<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/type<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;required<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/required<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;rtexprvalue<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/rtexprvalue<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/attribute<span style="font-weight: bold; color: black;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;dynamic-attributes<span style="font-weight: bold; color: black;">&gt;</span></span></span>true<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/dynamic-attributes<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/tab<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p>In case of TAG FILES</p>

<div class="wp_syntax"><div class="code"><pre>&lt;%@ tag body-content=&quot;empty&quot; dynamic-attributes=&quot;tagAttrs&quot; %&gt;</pre></div></div>

<p><strong>BodyTagSupport Class</strong> : This is just to work with the actual body content.<br />
There is one more return value for the <code>doStartTag()</code> : EVAL_BODY_BUFFERED (default return for the BodyTagSupport class).<br />
When EVAL_BODY_BUFFERED is returned, <code>setBodyContent()</code> &#038; <code>doInitBody()</code> called before evaluate the body.</p>
<p><strong>Nesting Tags</strong> : How to access parent tag? ==> using <code>getParent()</code></p>

<div class="wp_syntax"><div class="code"><pre class="java"><span style="color: #808080; font-style: italic;">//Getting top most tag handler</span>
Tag parent = getParent<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">While</span> <span style="color: #66cc66;">&#40;</span>parent <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	parent = parent.<span style="color: #006600;">getParent</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
	nestLevel++<span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><strong>Using <code>getParent()</code>, a classic can access only classic tag parents, and a simple tag can access either a classic or simple parent.</strong></p>
<p>If you want to access child from the parent: there is no predefined method. You will need to create custom method for the parent Tag class &#038; call it from the child Tag class by getting getParent and call the method. Store child data to parent class using the method.</p>
<p><strong>findAncestorWithClass(Tag,class of ancestor Tag you want to search)</strong><br />
This searches Tag parent until the class matches. This function does not belong to interface but to final classes (SimpleTagSupport, TagSupport, BodyTagSupport)</p>

<div class="wp_syntax"><div class="code"><pre>&lt;%@ attribute name=&quot;extra&quot; fragment=&quot;true&quot; %&gt;
&lt;jsp:invoke fragment='extra'&gt;</pre></div></div>

<p>&lt;jsp:invoke &gt; ==>  just like processing tag body but attribute fragment ?? Need to check further.</p>
<p><strong>Also SimpleTagSupport &#038; TAG FILE do not support 'JSP' type for &lt;body-content&gt;. But with classic handler TagSupport &#038; BodyTagSupport, 'JSP' can be used for &lt;body-content&gt;</strong></p>
<p><a href='http://code.neox.net/2008/05/01/scwcd-cram-sheet-8-web-deployment-and-security/'>(*) Next: [SCWCD] Cram Sheet 8 - Web Deployment and Security</a></p>
]]></content:encoded>
			<wfw:commentRss>http://code.neox.net/2008/04/29/scwcd-cram-sheet-7-using-jstl/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>[SCWCD] Cram Sheet 6 &#8211; using JSTL</title>
		<link>http://code.neox.net/2008/04/26/scwcd-cram-sheet-6-using-jstl/</link>
		<comments>http://code.neox.net/2008/04/26/scwcd-cram-sheet-6-using-jstl/#comments</comments>
		<pubDate>Sat, 26 Apr 2008 21:26:17 +0000</pubDate>
		<dc:creator>HanaDaddy</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[SCWCD]]></category>

		<guid isPermaLink="false">http://code.neox.net/?p=22</guid>
		<description><![CDATA[Chapter9 using JSTL
JSTL is not part of JSP 2.0 spec. (jstl.jar &#038; standard.jar copy needed)
(*) &#60;c:out&#62;

&#60;c:out value='${pageContent.currentTip}' escapeXml=&#34;true&#34; default=&#34;No tip&#34; /&#62;


escapeXML: when true,  escapes HTML special characters (&#60;,&#62;,&#038;,&#8217;,&#8221;) and default value is true.
default: attribute is to show default value when the value attribute data is null. Or default value can be defined in the [...]]]></description>
			<content:encoded><![CDATA[<h2>Chapter9 using JSTL</h2>
<p>JSTL is not part of JSP 2.0 spec. (jstl.jar &#038; standard.jar copy needed)</p>
<p>(*) <strong><code>&lt;c:out&gt;</code></strong></p>

<div class="wp_syntax"><div class="code"><pre>&lt;c:out value='${pageContent.currentTip}' escapeXml=&quot;true&quot; default=&quot;No tip&quot; /&gt;</pre></div></div>

<ul>
<li>escapeXML: when true,  escapes HTML special characters (&lt;,&gt;,&#038;,&#8217;,&#8221;) and default value is true.</li>
<li>default: attribute is to show default value when the value attribute data is null. Or default value can be defined in the body.</li>
</ul>
<p>(*) <strong><code>&lt;c:forEach&gt;</code></strong></p>

<div class="wp_syntax"><div class="code"><pre>&lt;c:forEach var=&quot;movie&quot; items=&quot;${movieList}&quot; varStatus=&quot;info&quot;&gt;
	&lt;tr&gt;&lt;td&gt;${info.count}&lt;/td&gt;&lt;td&gt;${movie}&lt;/td&gt;&lt;/tr&gt;
&lt;/c:forEach&gt;</pre></div></div>

<ul>
<li>Items: array, collection, map, comma delimited string</li>
<li>varStatus: extra object that you can get count information.</li>
<li><code>&lt;c:forEach&gt;</code> can be nested.
</ul>
<p>(*) <strong><code>&lt;c:if&gt;</code></strong></p>

<div class="wp_syntax"><div class="code"><pre>&lt;c:if test=&quot;${userType eq 'member'}&quot; &gt;
	&lt;jsp:include page=&quot;input.jsp&quot; /&gt;
&lt;/c:if&gt;</pre></div></div>

<p><span id="more-22"></span></p>
<p>(*) <strong><code>&lt;c:choose&gt;, &lt;c:when&gt;, &lt;c:otherwise&gt;</code></strong></p>

<div class="wp_syntax"><div class="code"><pre>&lt;c:choose&gt;
	&lt;c:when test=&quot;${userPref == 'performance'}&quot; &gt;
		…
	&lt;/c:when&gt;
	&lt;c:when test=&quot;${userpref == 'safety'}&quot; &gt;
		…
	&lt;/c:when&gt;
	&lt;c:otherwise&gt; … &lt;/c:otherwise&gt;  
&nbsp;
&lt;/c:choose&gt;</pre></div></div>

<p>&lt;c:otherwise&gt; is not a mandatory item within &lt;c:choose&gt;</p>
<p>(*) <strong>&lt;c:set &gt;</strong></p>
<ol>
<li>Setting attribute variable &#8216;var&#8217;

<div class="wp_syntax"><div class="code"><pre>&lt;c:set var=&quot;userlevel&quot; scope=&quot;session&quot; value=&quot;admin&quot; /&gt;</pre></div></div>

<p>When the attribute &#8216;userlevel&#8217; does not exist, it will create one within the session scope only if value is not null.</p>
<ul>
<li>Scope : it is optional. Default is page scope</li>
<li>Value : it may not be string. It can be object defined using EL ${object}</li>
</ul>
<p><code>&lt;c:set var="userlevel" scope="session"&gt;admin&lt;/c:set&gt;</code><br />
*Using data in the body as the value when body is used.</p>
<p>*If value is null, the var is removed even if it was previously defined!
</li>
<li>using &#8216;target&#8217; Setting target for Map and Bean object. (Not for array and list)

<div class="wp_syntax"><div class="code"><pre>&lt;c:set target=&quot;${PetMap}&quot; property=&quot;dogName&quot; value=&quot;Clover&quot; /&gt;</pre></div></div>

<p>If the target expression is null, container throws exception.<br />
Target should be the actual object. So  do no use ID names(string) but EL expression to reference real object.<br />
Even if target object exists, but propery name does not, Exception will be thrown.
</li>
</ol>
<p>(*) <strong><code>&lt;c:remove&gt;</code></strong></p>

<div class="wp_syntax"><div class="code"><pre>&lt;c:remove var=&quot;userStatus&quot; scope=&quot;request&quot; /&gt;</pre></div></div>

<p>The var must be string , can&#8217;t be an expression.<br />
If scope not defined, the named attribute is removed from all scopes.</p>
<p>(*) <strong><code>&lt;c:import&gt;</code></strong></p>

<div class="wp_syntax"><div class="code"><pre>&lt;c:import url=http://www.yahoo.com/index.html /&gt;</pre></div></div>

<p>This tag can import outside url page. &lt;c:import&gt; support local and remote file.</p>
<p>It is similar to &lt;jsp:import&gt; &#038; &lt;jsp:param&gt; . But &lt;jsp:import&gt; supports only local file.</p>

<div class="wp_syntax"><div class="code"><pre>&lt;c:import url=&quot;include.jsp&quot; &gt;
	&lt;c:param name=&quot;subtitle&quot; value=&quot;This is subtitle&quot; /&gt;
&lt;/c:import&gt;</pre></div></div>

<p>If the URL is local resource , the &lt;c:param&gt; will be available as local variable in the local resource.<br />
If the URL is remote website, the &lt;c:param&gt; value will be passed as query string.</p>
<p>(*) <strong><code>&lt;c:redirect&gt;</code></strong></p>

<div class="wp_syntax"><div class="code"><pre>&lt;c:redirect url=http://www.yahoo.com&quot; &gt;
	&lt;c:param name=&quot;query_name&quot; value=&quot;query_value&quot; /&gt;
&lt;/c:redirect&gt;</pre></div></div>

<p>Same as reponse.sendRedirect(&#8221;&#8230;&#8221;);  Client Redirect.</p>
<p>(*) <strong><code>&lt;c:url&gt;</code></strong></p>

<div class="wp_syntax"><div class="code"><pre>&lt;c:url value=&quot;/output.jsp&quot;  var=&quot;tempUrl&quot; /&gt;</pre></div></div>

<p>Just like encodeURL(), this element adds jsessionid to the URL if cookie is disabled.<br />
The actual url is stored into Var name and it is used to refer to the actual URL at the bottom of jsp page.</p>

<div class="wp_syntax"><div class="code"><pre>&lt;c:url value=&quot;/test.jsp&quot; &gt;
	&lt;c:param name=&quot;firstname&quot; value=&quot;${first}&quot; /&gt;
	&lt;c:param name=&quot;lastname&quot; value=&quot;${last}&quot; /&gt;
&lt;/c:url&gt;</pre></div></div>

<p>In order to encode  the query string, you need to use &lt;c:param&gt;  on each name and value pair. (not like encodeURL())</p>
<h3>(*) Error page</h3>
<p><code>&lt;%@ page isErrorPage ="true" &gt;</code> says this page is only used to show when error occurs. This makes exception implicit object available (scriplet ==> exception object , EL ==> ${pageContext.exception} )<br />
&lt;%@ page errorPage =&#8221;errorPage.jsp&#8221;&gt; If error occurs in this JSP page, forward to the error page.</p>
<p><strong>DD</strong></p>

<div class="wp_syntax"><div class="code"><pre>&lt;error-page&gt;
	&lt;exception-type&gt;java.lang.Throwable&lt;/exception-type&gt; &lt;!-- Throwable catch means to catch all exception--&gt;
	&lt;location&gt;/errorPage.jsp&lt;/location&gt;
&lt;/error-page&gt;
&lt;error-page&gt;
	&lt;error-code&gt;404&lt;/error-code&gt;
	&lt;location&gt;/404page.jsp&lt;/location&gt;
&lt;/error-page&gt;</pre></div></div>

<p>You can make the exception an attribute with in the same JSP page</p>

<div class="wp_syntax"><div class="code"><pre>&lt;c:catch var=&quot;myException&quot;&gt;
	Inside the catch…
	&lt;% int x= 10/0 ; %&gt;
&lt;/c:catch&gt;
&lt;c:if test=&quot;${myException} != null&quot; &gt;
	There was an exception: ${myException.message} &lt;br&gt;
&lt;/c:if&gt;</pre></div></div>

<h3>(*) Custom Tag Library</h3>
<p><strong>TLD FILE: /WEB-INF/anyname.tld (the file extension must be tld)</strong></p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;ISO-8859-1&quot;</span> <span style="font-weight: bold; color: black;">?&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;taglib</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/j2ee&quot;</span> 
	<span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span> 
	<span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd&quot;</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.0&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;tlib-version<span style="font-weight: bold; color: black;">&gt;</span></span></span>1.2<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/tlib-version<span style="font-weight: bold; color: black;">&gt;</span></span></span>  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!--mandatory--&gt;</span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;short-name<span style="font-weight: bold; color: black;">&gt;</span></span></span>MyTagTests<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/short-name<span style="font-weight: bold; color: black;">&gt;</span></span></span> <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!--mandatory--&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;uri<span style="font-weight: bold; color: black;">&gt;</span></span></span>MyTagTests<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/uri<span style="font-weight: bold; color: black;">&gt;</span></span></span>  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!--mandatory--&gt;</span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;tag<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;description<span style="font-weight: bold; color: black;">&gt;</span></span></span>Simple Test<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/description<span style="font-weight: bold; color: black;">&gt;</span></span></span> <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- optional --&gt;</span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;name<span style="font-weight: bold; color: black;">&gt;</span></span></span>SimpleTest<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/name<span style="font-weight: bold; color: black;">&gt;</span></span></span> <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- require --&gt;</span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;tag-class<span style="font-weight: bold; color: black;">&gt;</span></span></span>com.example.web.tag.TestSimpleTag<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/tag-class<span style="font-weight: bold; color: black;">&gt;</span></span></span> <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Required --&gt;</span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;body-content<span style="font-weight: bold; color: black;">&gt;</span></span></span>scriptless<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/body-content<span style="font-weight: bold; color: black;">&gt;</span></span></span> <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- required! --&gt;</span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;attribute<span style="font-weight: bold; color: black;">&gt;</span></span></span>  <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- attribute tag is required for each attribute needed --&gt;</span></span>
			<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;name<span style="font-weight: bold; color: black;">&gt;</span></span></span>arg1<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/name<span style="font-weight: bold; color: black;">&gt;</span></span></span>			
			<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;required<span style="font-weight: bold; color: black;">&gt;</span></span></span>true<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/required<span style="font-weight: bold; color: black;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;rtexprvalue<span style="font-weight: bold; color: black;">&gt;</span></span></span>true<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/rtexprvalue<span style="font-weight: bold; color: black;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/attribute<span style="font-weight: bold; color: black;">&gt;</span></span></span>		
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/tag<span style="font-weight: bold; color: black;">&gt;</span></span></span>	
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/taglib<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p><strong>JSP FILE: /tagusing.jsp</strong></p>

<div class="wp_syntax"><div class="code"><pre>&lt;%@ taglib prefix=&quot;mytag&quot; uri=&quot;MyTagTests&quot; %&gt;</pre></div></div>

<p>The uri should be the actual tld file path (/WEB-INF/anyname.tld) or the &lt;uri&gt; element name from the tld file.</p>

<div class="wp_syntax"><div class="code"><pre>&lt;mytag:SimpleTest arg1=&quot;${value}&quot; &gt;
	Here is the body
&lt;/mytag:SimpleTest&gt;</pre></div></div>

<ul>
<li>using the prefix defined in the taglib.
<li>Attribute name is defined in the <code>&lt;attribute&gt;</code> . If <code>&lt;required&gt;</code> is true and you didn&#8217;t use the attribute , you get Exception.
<li>Body is used since <code>&lt;body-content&gt;</code> is not empty. If <code>&lt;body-content&gt;</code> is empty but body exists, you get Exception.</li>
</ul>
<p><strong>Actual tag class java source (simple tag): /WEB-INF/classes/com/example/web/tag/TestSimpleTag.class</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java"><span style="color: #000000; font-weight: bold;">package</span> com.<span style="color: #006600;">example</span>.<span style="color: #006600;">web</span>.<span style="color: #006600;">tag</span><span style="color: #66cc66;">;</span>
<span style="color: #a1a100;">import javax.servlet.jsp.JspException;</span>
<span style="color: #a1a100;">import javax.servlet.jsp.tagext.SimpleTagSupport;</span>
<span style="color: #a1a100;">import java.io.IOException;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TestSimpleTag <span style="color: #000000; font-weight: bold;">extends</span> SimpleTagSupport <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #aaaadd; font-weight: bold;">String</span> arg1<span style="color: #66cc66;">;</span>
&nbsp;
    @override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> doTag<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JspException, <span style="color: #aaaadd; font-weight: bold;">IOException</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">//must be overriden</span>
        <span style="color: #808080; font-style: italic;">// Write something to output</span>
        <span style="color: #aaaadd; font-weight: bold;">String</span> result=<span style="color: #ff0000;">&quot;Body is empty&quot;</span><span style="color: #66cc66;">;</span>
        JspFragment jf = getJspBody<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>jf <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
            jf.<span style="color: #006600;">invoke</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span> <span style="color: #808080; font-style: italic;">// evaluating the tag body</span>
            result=<span style="color: #ff0000;">&quot;Body is not empty!&quot;</span><span style="color: #66cc66;">;</span>
        <span style="color: #66cc66;">&#125;</span>
        getJspContext<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getOut</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;&lt;br&gt;ARG: &quot;</span>+<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">arg1</span> + <span style="color: #ff0000;">&quot;&lt;br&gt;&quot;</span> + result<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>	
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> setArg1<span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">String</span> arg<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>  <span style="color: #808080; font-style: italic;">//Create a setter method for each Attribute</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">arg1</span>=arg<span style="color: #66cc66;">;</span>
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>* Tag file <code>&lt;rtexprvalue&gt;</code> true ==> means OK to use both EL and scripting Expression.<br />
The default value is false for  <code>&lt;rtexprvalue&gt;</code>. When you use EL when <code>&lt;rtexprvalue&gt;</code>=false, you get exception.</p>
<p>Below three tags are all the same.</p>

<div class="wp_syntax"><div class="code"><pre>&lt;mytag:SimpleTest arg1=&quot;${name}&quot; /&gt;
&lt;mytag:SimpleTest arg1=&quot;&lt;%=request.getAttribute(&quot;name&quot;)%&gt;&quot; /&gt;
&lt;mytag:SimpleTest &gt;
	&lt;jsp:attribute name=&quot;arg1&quot;&gt;${name}&lt;/jsp:attribute&gt;
&lt;/mytag:SimpleTest&gt;</pre></div></div>

<p><code>&lt;jsp:attribute&gt;</code> can be used inside of tag body for tag&#8217;s each attribute.</p>
<p>*Values for <code>&lt;body-content&gt;</code></p>
<ul>
<li>empty: tag must not have body</li>
<li>scriptless: no scriptlets allowed, but EL, customs and standard tags are OK.</li>
<li>tagdependent: body treated as plain text</li>
<li>JSP : All is allowed </li>
</ul>
<p>* <code>&lt;uri&gt;</code> is just a name , not a location!</p>
<p>* You had to define taglib in the OLD DD specification</p>

<div class="wp_syntax"><div class="code"><pre>&lt;taglib&gt;
	&lt;taglib-uri&gt;MyTagTests&lt;/taglib-uri&gt;
	&lt;taglib-location&gt;/WEB-INF/anyname.tld&lt;/taglib-location&gt;
&lt;/taglib&gt;</pre></div></div>

<p>* You can&#8217;t use below prefix in taglib directive : <strong>jsp, jspx, java, javax, servlet, sun, sunw</strong></p>
<p><a href='http://code.neox.net/2008/04/29/scwcd-cram-sheet-7-using-jstl/'>(*) Next: [SCWCD] Cram Sheet 7 &#8211; Custom Tag Development</a></p>
]]></content:encoded>
			<wfw:commentRss>http://code.neox.net/2008/04/26/scwcd-cram-sheet-6-using-jstl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk (enhanced)

Served from: code.neox.net @ 2012-02-07 13:09:38 -->
