<?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>JavaBeat &#187; JSP</title>
	<atom:link href="http://www.javabeat.net/category/java-j2ee/jsp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javabeat.net</link>
	<description>Java Technology News</description>
	<lastBuildDate>Mon, 13 May 2013 20:10:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>What is load on startup element in web.xml file</title>
		<link>http://www.javabeat.net/2013/02/what-is-load-on-startup-element-in-web-xml-file/</link>
		<comments>http://www.javabeat.net/2013/02/what-is-load-on-startup-element-in-web-xml-file/#comments</comments>
		<pubDate>Thu, 21 Feb 2013 04:33:47 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[JSP]]></category>
		<category><![CDATA[Servlets]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=5941</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>specify the order in which we want to initialize various Servlets. Like first initialize Servlet1 then Servlet2 and so on. This is accomplished by specifying a numeric value for the  &#60;load-on-startup&#62; tag. &#60;load-on-startup&#62; tag specifies that the servlet should be loaded automatically when the web application is started. The value is a single positive integer, [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><a id="dd_start"></a><p>specify the order in which we want to initialize various Servlets. Like first initialize Servlet1 then Servlet2 and so on.<br />
This is accomplished by specifying a numeric value for the  &lt;load-on-startup&gt; tag. &lt;load-on-startup&gt; tag specifies that the servlet should be loaded<br />
automatically when the web application is started.</p>
<p>The value is a single positive integer, which specifies the loading order. Servlets with lower values are loaded before servlets with<br />
higher values (ie: a servlet with a load-on-startup value of 1 or 5 is loaded before a servlet with a value of 10 or 20). When loaded, the init() method of the servlet is called. Therefore this tag provides a good way to do the following:</p>
<p>start any daemon threads, such as a server listening on a TCP/IP port, or a background maintenance thread perform initialisation of the application, such as parsing a settings file which provides data to other servlets/JSPs If no &lt;load-on-startup&gt; value is specified, the servlet will be loaded when the container decides it needs to be loaded &#8211; typically on it&#8217;s first access. This is suitable for servlets that don&#8217;t need to perform special initialisation.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p>I hope that clears all the doubts regarding &lt;load-on-startup&gt; in web.xml.</p>
<div class='dd_outer'><div class='dd_inner'><div id='dd_ajax_float'><div class='dd_button_v'><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="http%3A%2F%2Fwww.javabeat.net%2Fcategory%2Fjava-j2ee%2Fjsp%2Ffeed%2F" send="false" show_faces="false"  layout="box_count" width="50"  ></fb:like></div><div style='clear:left'></div><div class='dd_button_v'><script type='text/javascript' src='https://apis.google.com/js/plusone.js'></script><g:plusone size='tall' href='http://www.javabeat.net/category/java-j2ee/jsp/feed/'></g:plusone></div><div style='clear:left'></div><div class='dd_button_v'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.javabeat.net/category/java-j2ee/jsp/feed/" data-count="vertical" data-text="JSP" data-via="javabeat" ></a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style='clear:left'></div><div class='dd_button_extra_v'><script type="text/javascript">jQuery(document).load(function(){ stLight.options({publisher:'bab47279-62c9-46af-addc-79fd1fe8fee0'}); });</script><div class="st_email_custom"><span id='dd_email_text'>email</span></div></div><div style='clear:left'></div><div class='dd_button_extra_v'><div id='dd_print_button'><span id='dd_print_text'><a href='javascript:window:print()'>print</a></span></div></div><div style='clear:left'></div></div></div></div><script type="text/javascript">var dd_offset_from_content = 44; var dd_top_offset_from_content = 0;</script><script type="text/javascript" src="http://www.javabeat.net/wp-content/plugins/digg-digg//js/diggdigg-floating-bar.js?ver=5.3.0"></script><div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2013/02/what-is-load-on-startup-element-in-web-xml-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Core Tags in JSTL</title>
		<link>http://www.javabeat.net/2011/05/core-tags-in-jstl/</link>
		<comments>http://www.javabeat.net/2011/05/core-tags-in-jstl/#comments</comments>
		<pubDate>Sun, 22 May 2011 00:39:47 +0000</pubDate>
		<dc:creator>JavaBeat</dc:creator>
				<category><![CDATA[JSP]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/examples/?p=322</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>[ In the second part of this tutorial on JSTL, the author explains how the tags in the core-group can be used in JSP pages, with a number of simpleexamples.] We are now ready toexperiment with all the tags in the ‘core’ library. The core tags have the following uniform‘uri’. ‘http://java.sun.com/jstl/core&#039; =============================== ( However, in [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p class="MsoNormal"><span class="GramE"><span>[</span><span> In</span></span><span> the second part of this<br />
tutorial on JSTL, the author explains how the tags in the core-group can be<br />
used in JSP pages, with a number of simple<span></span>examples.]</span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>We are now ready <span class="GramE">to<span></span>experiment</span> with all the tags in the<br />
‘core’ library. The core tags have the following <span class="GramE">uniform<span></span>‘<span class="SpellE">uri</span>’</span>.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>‘<span class="GramE"><b>http</b></span><b>://<span class="SpellE">java.sun.com/jstl/core</span>&#039;</b></span></p>
<p class="MsoNormal"><b><span>===============================</span></b></p>
<p class="MsoNormal"><span class="GramE"><span>( However</span></span><span>, in the book by Hans<br />
Bergsten<span></span><span class="SpellE">titled,&quot;Java</span><br />
Server Pages&quot; ( third edition), (<span class="SpellE">OReilly</span> pub)the<br />
<span class="SpellE">uri</span> is consistently given as :</span></p>
<p class="MsoNormal"><span>&#039;<span class="GramE">http</span>://<span class="SpellE">java.sun.com/<b>jsp/</b>jstl/core&#039;.It</span></span><span> looks as if there has been some<br />
change in specification and grammar, after it was published.</span></p>
<p class="MsoNormal"><span>This<br />
appears to be wrong <span class="GramE">as<span></span>the</span> server threw<span></span><span class="SpellE">exception.The</span> correct <span class="SpellE">uri</span> is :</span></p>
<div>
<p class="MsoNormal" style="border: medium none;padding: 0in;text-align: justify"><span>&#039;<span class="GramE"><b>http</b></span><b>://<span class="SpellE">java.sun.com/jstl/core</span>&#039;</b>.)</span></p>
</div>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>The<br />
prefix <span class="GramE">is<span></span>‘c</span>:’</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>The following tags are available in the<br />
‘core’ library.</span></p>
<p class="MsoNormal"><span class="GramE"><span>( Remember</span></span><span> them as a dozen!).</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span><b><span></span>&lt;<span class="SpellE">c<span class="GramE">:set</span></span></b></span></p>
<p class="MsoNormal"><b><span><span></span>&lt;<span class="SpellE">c<span class="GramE"> <img src='http://www.javabeat.net/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> ut</span></span></span></b></p>
<p class="MsoNormal"><b><span><span></span>&lt;<span class="SpellE">c<span class="GramE">:if</span></span><span></span>test= “<span></span></span></b></p>
<p class="MsoNormal"><b><span><span></span>&lt;<span class="SpellE">c<span class="GramE">:choose</span></span><span></span>,<span></span>&lt;<span class="SpellE">c:when</span> ,<span></span>&lt;<span class="SpellE">c:otherwise</span></span></b></p>
<p class="MsoNormal"><b><span><span></span>&lt;<span class="SpellE">c<span class="GramE">:forEach</span></span></span></b></p>
<p class="MsoNormal"><b><span><span></span>&lt;<span class="SpellE">c<span class="GramE">:forTokens</span></span></span></b></p>
<p class="MsoNormal"><b><span><span></span>&lt;<span class="SpellE">c<span class="GramE">:import</span></span></span></b></p>
<p class="MsoNormal"><b><span><span></span>&lt;<span class="SpellE">c<span class="GramE">:url</span></span></span></b></p>
<p class="MsoNormal"><b><span><span></span>&lt;<span class="SpellE">c<span class="GramE">:redirect</span></span></span></b></p>
<p class="MsoNormal"><b><span><span></span>&lt;<span class="SpellE">c<span class="GramE">:param</span></span></span></b></p>
<p class="MsoNormal"><span><span></span>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</span></p>
<p class="MsoNormal"><span>We<br />
will now see simplest illustrations for the above <span class="SpellE">tags.There</span><br />
are a dozen demos, to bring out the features of each of these tags.</span></p>
<p class="MsoNormal"><span>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<span></span></span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><span class="GramE"><b><span>demo1.jsp<span></span></span></b><span>uses</span></span><span><span></span><b>&lt;<span class="SpellE">c:set</span></b>&amp;<br />
<b><span></span>&lt;<span class="SpellE">c:out</span><span></span></b>tags.</span></p>
<p class="MsoNormal"><span class="GramE"><span>:We</span></span><span> create demo1.jsp<span></span>as:</span></p>
<p class="MsoNormal"><span>e:tomcat5webappsrootdemo1.jsp</span></p>
<p class="MsoNormal"><span>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</span></p>
<p class="MsoNormal"><span>//<span></span><b>demo1.jsp</b></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>&lt;%@<br />
page <span class="SpellE">contentType</span>=&quot;text/html&quot; %&gt;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>&lt;%@<br />
<span class="SpellE">taglib</span><span></span>prefix=&quot;c&quot;<span></span><span class="SpellE"><b>uri</b></span><b>=&quot;http://java.sun.com/jstl/core<span class="GramE">&quot;<span></span>%</span>&gt;</b></span></p>
<p class="MsoNormal"><b><span></span></b></p>
<p class="MsoNormal"><span>&lt;<span class="GramE">html</span>&gt;</span></p>
<p class="MsoNormal"><span>&lt;body<span></span><span class="SpellE">bgcolor</span>=<span class="SpellE">lightblue</span>&gt;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>&lt;form<span></span>method=<span class="GramE">post<span></span>action</span>=&quot;demo1.jsp&quot;&gt;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>NAME &lt;<span class="GramE">input<span></span>type</span>=text<span></span>name=&quot;text1&quot;&gt;&lt;<span class="SpellE">br</span>&gt;</span></p>
<p class="MsoNormal"><span><span></span>PLACE&lt;<span class="GramE">input<span></span>type</span>=text<span></span>name=&quot;text2&quot;&gt;&lt;<span class="SpellE">br</span>&gt;</span></p>
<p class="MsoNormal"><span><span></span>&lt;input type=submit&gt;</span></p>
<p class="MsoNormal"><span><span></span>&lt;/form&gt; </span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><span><span></span><span class="GramE">NAME<b>:</b></span><b>&lt;<span class="SpellE">c:out</span></b><span></span>value<b>=&quot;${param.text1}&quot;</b><span></span>/&gt;&lt;<span class="SpellE">br</span>&gt;</span></p>
<p class="MsoNormal"><span><span></span><span class="GramE">PLACE<b>:</b></span><b>&lt;<span class="SpellE">c:out</span><span></span></b>value<b>=&quot;${param.text2}&quot;<span></span></b>/&gt;</span></p>
<p class="MsoNormal"><span>&lt;/body&gt;</span></p>
<div>
<div style="border-style: none none double;border-color: -moz-use-text-color -moz-use-text-color windowtext;border-width: medium medium 2.25pt;padding: 0in 0in 1pt">
<p class="MsoNormal" style="border: medium none;padding: 0in;text-align: justify"><span>&lt;/html&gt;</span></p>
<p class="MsoNormal" style="border: medium none;padding: 0in;text-align: justify"><span></span></p>
</div>
</div>
<p class="MsoNormal"><span>In all the<br />
previous examples, we invoked the JSP file through a <span class="GramE">html<span></span>file</span>. But, in demo1.jsp, we <span class="GramE">are<span></span>posting</span> the page<br />
to itself.( in asp.net style!).<span class="GramE">( but</span> there is no<br />
&#039;retention of data&#039; , unlike asp.net).</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>We start<br />
Tomcat5, and type the <span class="SpellE">url</span><span class="GramE">as :</span></span></p>
<p class="MsoNormal"><span><span></span>‘<span class="GramE">http</span>://localhost:8080/demo1.jsp’.<span></span><span class="GramE">in</span> the <span class="SpellE">browser.We</span> get a form with two text boxes and a submit<br />
button. We fill up the textboxes with ‘name’ and ‘place’ and <span class="SpellE">submit.The</span> demo1.jsp executes and displays <span class="GramE">the<span></span>values</span> entered by<br />
the <span class="SpellE">user.due</span> to the JSTL tags </span></p>
<p class="MsoNormal"><b><span>&lt;<span class="SpellE">c<span class="GramE"> <img src='http://www.javabeat.net/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> ut</span></span><span></span>value=”${param.text1}</span></b><span><span></span>/&gt;<span></span>etc.</span></p>
<p class="MsoNormal"><span>That is<br />
about our first and introductory example.</span></p>
<p class="MsoNormal"><span>&#8212;&#8212;&#8212;&#8211;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</span></p>
<p class="MsoNormal"><span><span></span>The second example is very important. When<br />
the user enters data in a number of fields, it is tedious to collect the data<br />
and transfer it to <span class="SpellE">jsp</span> page for processing. In our<br />
example, we are collecting data about a player<span class="GramE">,<span></span>such</span> as his name, place and game. We<br />
can have much more but we are restricting for space considerations. JSP has an<br />
action <span class="GramE">tag ,</span> known as &#039;<span class="SpellE"><b>jsp:setProperty</b></span><b>&#039;</b>.<br />
Using this along with a standard <span class="SpellE">javabean</span>, we can<br />
extract data and transfer it to our program in a single step.</span></p>
<p class="MsoNormal"><span>The syntax<br />
is</span></p>
<p class="MsoNormal"><b><span>&lt;<span class="SpellE">jsp<span class="GramE">:useBean</span></span></span></b><span></span></p>
<p class="MsoNormal"><span><span></span><span class="GramE">id</span>=&quot;bean1&quot;<span></span>class=&quot;<span class="SpellE">ourbeans.player</span>&quot;<span></span>&gt;</span></p>
<p class="MsoNormal"><span><span></span><b>&lt;<span class="SpellE">jsp<span class="GramE">:setProperty</span></span></b></span></p>
<p class="MsoNormal"><span><span></span><span class="GramE">name</span>=&quot;bean1&quot;<span></span>property=&quot;*&quot;<span></span>/&gt;</span></p>
<p class="MsoNormal"><span>&lt;/<span class="SpellE">jsp<span class="GramE">:useBean</span></span>&gt;</span></p>
<p class="MsoNormal"><span> <img src='http://www.javabeat.net/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /><br />
the * sign denotes &#039;all&#039;).</span></p>
<p class="MsoNormal"><span>&#8212;&#8211;</span></p>
<p class="MsoNormal"><span><span></span>But, we should first create the &#039;player &#039; bean<br />
with all the attributes and<b> getter &amp; setter methods</b>, as shown.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><b><span>/<span class="GramE">/<span></span><span class="SpellE">player.java</span></span></span></b></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span class="GramE"><b><span>package</span></b></span><b><span><span class="SpellE">ourbeans</span>;</span></b></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span class="GramE"><span>public</span></span><span> class player</span></p>
<p class="MsoNormal"><span>{</span></p>
<p class="MsoNormal"><span><span></span>String<span></span>name;</span></p>
<p class="MsoNormal"><span><span></span>String<span></span>place;</span></p>
<p class="MsoNormal"><span><span></span>String<span></span>game;</span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span><span class="GramE">public</span> player()</span></p>
<p class="MsoNormal"><span><span></span>{</span></p>
<p class="MsoNormal"><span><span></span><span class="GramE">name</span>=&quot;<span></span>&quot;;</span></p>
<p class="MsoNormal"><span><span></span><span class="GramE">place</span>=&quot;<br />
&quot;;</span></p>
<p class="MsoNormal"><span><span></span><span class="GramE">game</span>=&quot;<br />
&quot;;<span></span></span></p>
<p class="MsoNormal"><span><span></span>}</span></p>
<p class="MsoNormal"><span>//&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</span></p>
<p class="MsoNormal"><span><span></span><span class="GramE">public</span> void<b><span class="SpellE">setName</span></b>(String a)</span></p>
<p class="MsoNormal"><span><span></span>{<span></span><span class="GramE">name=</span>a; }</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span><span class="GramE">public</span> void <span class="SpellE"><b>setPlace</b></span>(String b)</span></p>
<p class="MsoNormal"><span><span></span>{<span></span><span class="GramE">place=</span>b; }</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span><span class="GramE">public</span> void <span class="SpellE"><b>setGame</b></span><b>(</b>String c)</span></p>
<p class="MsoNormal"><span><span></span><span class="GramE">{<span></span>game</span>=c;<span></span>}</span></p>
<p class="MsoNormal"><span>//&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><span><span></span><span class="GramE">public</span> String<span></span><span class="SpellE"><b>getName</b></span>()</span></p>
<p class="MsoNormal"><span><span></span><span class="GramE">{ return</span><span></span>name; }</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span><span class="GramE">public</span> String<span></span><span class="SpellE"><b>getPlace</b></span><b>()</b></span></p>
<p class="MsoNormal"><span><span></span><span class="GramE">{ return</span><span></span>place; }</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span><span class="GramE">public</span> String<span></span><b><span></span><span class="SpellE">getGame</span>()</b></span></p>
<p class="MsoNormal"><span><span></span><span class="GramE">{ return</span><span></span>game; }</span></p>
<p class="MsoNormal"><span>}</span></p>
<p class="MsoNormal"><span>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</span></p>
<p class="MsoNormal"><span><span></span>In demo2.jsp, we collect the data and then <span class="GramE">display<span></span>the</span> data<br />
entered by the user.</span></p>
<p class="MsoNormal"><span>Note that<br />
instead of {param.text1}, we are using {bean1.name}. We should carefully name<br />
the html form controls with the corresponding attribute names given in the<br />
bean. We cannot name the controls as &#039;text1&#039; etc, now!</span></p>
<p class="MsoNormal"><span>&lt;<span class="SpellE">c<span class="GramE"> <img src='http://www.javabeat.net/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> ut</span></span><span></span>value<b>=&quot;${bean1.name}&quot;<span></span></b>/&gt;</span></p>
<p class="MsoNormal"><span>&lt;<span class="SpellE">c<span class="GramE"> <img src='http://www.javabeat.net/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> ut</span></span><span></span>value=&quot;${bean1.place}&quot;<span></span>/&gt;</span></p>
<p class="MsoNormal"><span>&lt;<span class="SpellE">c<span class="GramE"> <img src='http://www.javabeat.net/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> ut</span></span><span></span>value=&quot;${bean1.game}&quot;<span></span>/&gt;</span></p>
<p class="MsoNormal"><span>&#8212;</span></p>
<p class="MsoNormal"><span><span></span>We get correct result.</span></p>
<p class="MsoNormal"><span>=============================================</span></p>
<p class="MsoNormal"><b><span>//<span></span>demo2.jsp</span></b><span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span></span></p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p class="MsoNormal"><span>&lt;%@<br />
page <span class="SpellE">contentType</span>=&quot;text/html&quot; %&gt;</span></p>
<p class="MsoNormal"><span>&lt;%@<br />
<span class="SpellE">taglib</span> prefix=&quot;c&quot; </span></p>
<p class="MsoNormal"><span class="SpellE"><span>uri</span></span><span>=&quot;http://java.sun.com/jstl/core<span class="GramE">&quot;<span></span>%</span>&gt;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>&lt;<span class="GramE">html</span>&gt;</span></p>
<p class="MsoNormal"><span>&lt;<span class="GramE">body</span>&gt;</span></p>
<p class="MsoNormal"><span>&lt;form<br />
method=post<span></span><span></span>action=&quot;demo2.jsp&quot;&gt;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>&lt;<span class="SpellE">jsp<span class="GramE">:useBean</span></span> id=&quot;bean1&quot;<br />
class=&quot;<span class="SpellE">ourbeans.player</span>&quot;&gt;</span></p>
<p class="MsoNormal"><b><span>&lt;<span class="SpellE">jsp<span class="GramE">:setProperty</span></span></span></b><span>name=&quot;bean1&quot;<b><br />
property=&quot;*&quot;<span></span></b>/&gt;</span></p>
<p class="MsoNormal"><span>&lt;/<span class="SpellE">jsp<span class="GramE">:useBean</span></span>&gt;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>Name<br />
&lt;input<span></span>type=text<span></span><b><span></span>name=&quot;name</b>&quot;&gt;&lt;<span class="SpellE">br</span>&gt;</span></p>
<p class="MsoNormal"><span>Place&lt;<span class="GramE">input<span></span>type</span>=text<span></span><b>name=&quot;place&quot;</b>&gt;&lt;<span class="SpellE">br</span>&gt;</span></p>
<p class="MsoNormal"><span>Game&lt;input<span></span>type=text<span></span><b>name=&quot;game&quot;</b>&gt;&lt;<span class="SpellE">br</span>&gt;</span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><span>&lt;input<br />
type=submit&gt;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>&lt;/form&gt;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>Name:<br />
<b>&lt;<span class="SpellE">c<span class="GramE"> <img src='http://www.javabeat.net/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> ut</span></span></b>value=<b>&quot;${bean1.name}&quot;</b><span></span>/&gt;&lt;<span class="SpellE">br</span>&gt;</span></p>
<p class="MsoNormal"><span>Place:<br />
&lt;<span class="SpellE">c<span class="GramE"> <img src='http://www.javabeat.net/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> ut</span></span><br />
value=&quot;${bean1.place}&quot;<span></span>/&gt;&lt;<span class="SpellE">br</span>&gt;</span></p>
<p class="MsoNormal"><span>Game:<br />
&lt;<span class="SpellE">c<span class="GramE"> <img src='http://www.javabeat.net/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> ut</span></span><br />
value=&quot;${bean1.game}&quot;<span></span>/&gt;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>&lt;/body&gt;</span></p>
<p class="MsoNormal"><span>&lt;/html&gt;</span></p>
<p class="MsoNormal"><span>=============================================</span></p>
<p class="MsoNormal"><span>Once<br />
again, it will be noticed that there is no java code in this example, as<br />
everything is being done by tags, only<span class="GramE">..</span></span></p>
<p class="MsoNormal"><span>***********************************************</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>We<br />
are now ready to take up examples for <span class="GramE">&#039;condition&#039;<span></span>tags</span>.</span></p>
<p class="MsoNormal"><span><span></span>There are two types of &#039;condition tags&#039;.</span></p>
<p class="MsoNormal"><span class="GramE"><span>namely</span></span><span>, <b>&lt;<span class="SpellE">c:if</span>&gt;<span></span></b>&amp;<span></span><b>&lt;<span class="SpellE">c:choose</span></b>&gt;.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><b><span>In the<br />
third demo, we learn how to use the &lt;<span class="SpellE">c<span class="GramE">:if</span></span><span></span>tag</span></b><span>.</span></p>
<p class="MsoNormal"><span>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</span></p>
<p class="MsoNormal"><span>/<b>/demo3.jsp</b></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>&lt;%@<br />
page <span class="SpellE">contentType</span>=&quot;text/html&quot; %&gt;</span></p>
<p class="MsoNormal"><span>&lt;%@<br />
<span class="SpellE">taglib</span> prefix=&quot;c&quot; <span class="SpellE">uri</span>=&quot;http://java.sun.com/jstl/core<span class="GramE">&quot;<span></span>%</span>&gt;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>&lt;<span class="GramE">html</span>&gt;</span></p>
<p class="MsoNormal"><span>&lt;body<span></span><span class="SpellE">bgcolor</span>=<span class="SpellE">lightblue</span>&gt;</span></p>
<p class="MsoNormal"><span>&lt;form<span></span>method=post<span></span>action=demo3.jsp&gt;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>&lt;select<span></span>name=&quot;combo1&quot;&gt;</span></p>
<p class="MsoNormal"><span><span></span>&lt;option<span></span>value=&quot;<span class="SpellE">sam</span>&quot;&gt;<span class="SpellE">sam</span></span></p>
<p class="MsoNormal"><span><span></span>&lt;option<span></span><span></span>value=&quot;tom&quot;&gt;tom</span></p>
<p class="MsoNormal"><span>&lt;/select&gt;</span></p>
<p class="MsoNormal"><span>&lt;input<span></span>type=submit&gt;</span></p>
<p class="MsoNormal"><span>&lt;/form&gt;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><b><span>&lt;<span class="SpellE">c<span class="GramE">:set</span></span><span></span></span></b><span class="SpellE"><span>var</span></span><span>=&quot;s&quot;<span></span>value<b>=&quot;${param.combo1}&quot;<span></span></b>/&gt;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>&lt;<span class="SpellE"><b>c<span class="GramE"> <img src='http://www.javabeat.net/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> ut</span></b></span><br />
value=&quot;${s}&quot;<span></span>/&gt;</span></p>
<p class="MsoNormal"><span>&lt;<span class="SpellE"><span class="GramE">br</span></span>&gt;</span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><b><span>&lt;<span class="SpellE">c<span class="GramE">:if</span></span><span></span>test=&quot;${s<span></span><span class="SpellE">eq</span><span></span></span></b><span>&#039;<span class="SpellE">sam</span>&#039;<span></span><b>}&quot;<span></span>&gt; </b></span></p>
<p class="MsoNormal"><span>&lt;<span class="SpellE">c<span class="GramE"> <img src='http://www.javabeat.net/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> ut</span></span><span></span>value=&quot;Good<br />
Morning&#8230;SAM!&quot;<span></span>/&gt;</span></p>
<p class="MsoNormal"><b><span>&lt;/<span class="SpellE">c<span class="GramE">:if</span></span>&gt;</span></b></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><b><span>&lt;<span class="SpellE">c<span class="GramE">:if</span></span><span></span>test=&quot;${s<span></span></span></b><b><span><span></span>=<br />
=<span></span></span></b><span><span></span></span><span>&#039;tom&#039;<b>}&quot;<span></span></b>&gt;</span></p>
<p class="MsoNormal"><span>&lt;<span class="SpellE">c<span class="GramE"> <img src='http://www.javabeat.net/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> ut</span></span><span></span>value=&quot; How Are<br />
You?&#8230;.TOM!&quot;<span></span>/&gt;</span></p>
<p class="MsoNormal"><b><span>&lt;/<span class="SpellE">c<span class="GramE">:if</span></span>&gt;</span></b><span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>&lt;/body&gt;</span></p>
<div>
<div style="border-style: none none solid;border-color: -moz-use-text-color -moz-use-text-color windowtext;border-width: medium medium 1pt;padding: 0in 0in 1pt">
<p class="MsoNormal" style="border: medium none;padding: 0in;text-align: justify"><span>&lt;/html&gt;</span></p>
<p class="MsoNormal" style="border: medium none;padding: 0in;text-align: justify"><span>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</span></p>
<p class="MsoNormal" style="border: medium none;padding: 0in;text-align: justify"><span><span></span></span><span><span></span>There is a combo with two options, namely </span></p>
<p class="MsoNormal" style="border: medium none;padding: 0in;text-align: justify"><span>&#039;<span class="SpellE"><span class="GramE">sam</span></span>&#039; and &#039;tom&#039;. If the user<br />
selects &#039;<span class="SpellE">sam</span>&#039; and submits the form, he gets &#039;<span class="SpellE">GoodMorning</span> &#8230;SAM!&quot;. If he selects &#039;tom&#039; instead, he<br />
gets </span></p>
<p class="MsoNormal" style="border: medium none;padding: 0in;text-align: justify"><span>&#039;How<br />
are <span class="SpellE">you<span class="GramE">..</span>TOM</span>?<span class="GramE">&#039;.</span></span></p>
</div>
</div>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>The above code is no ‘Rocket-Science’ as<br />
American<span></span>authors <span class="SpellE">say!But</span><br />
, if we are careless<span></span>in typing the names<br />
‘<span class="SpellE">sam</span>’ or ‘tom’ in the test condition, we could spend<br />
hours together , trying to coax this code into functioning! We should not leave<br />
space after the single <span class="GramE">quote<span></span>in</span> the &#039;test expression&#039;. Second point worth noting in the above<br />
example is that we can use either <b>==</b><span class="GramE">( double</span> equal to) or <span class="SpellE"><b>eq</b></span><span></span>to test equality.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>***********************************************</span></p>
<p class="MsoNormal"><span>In<br />
the <b>fourth</b> example which follows, we take up &lt;<span class="SpellE">c<span class="GramE">:choose</span></span>&gt; tag.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>The<br />
syntax is: </span></p>
<p class="MsoNormal"><span>&lt;<span class="SpellE"><span class="GramE">c:</span>choose</span> &gt; </span></p>
<p class="MsoNormal"><span><span></span>&lt;<span class="SpellE">c<span class="GramE">:when</span></span><span></span>test=&quot;<span></span>&quot;<span></span>&gt;</span></p>
<p class="MsoNormal"><span><span></span>&lt;<span class="SpellE">c<span class="GramE"> <img src='http://www.javabeat.net/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> therwise</span></span>&gt;<span></span>something<span></span>&lt;/<span class="SpellE">c:otherwise</span>&gt;</span></p>
<p class="MsoNormal"><span><span></span>&lt;/<span class="SpellE">c<span class="GramE">:choose</span></span>&gt;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>The<br />
peculiarity to be noted here is that<span></span>unlike &lt;<span class="SpellE">c<span class="GramE">:if</span></span> ,<br />
where we had to explicitly<span></span>use &lt;<span class="SpellE">c:out</span> for printing , </span><span>no such &lt;<span class="SpellE">c:out</span><br />
has been used here., and yet the result is displayed,</span></p>
<p class="MsoNormal"><span class="GramE"><span>because</span></span><span> &#039;choose&#039; includes &#039;displaying&#039;..</span></p>
<p class="MsoNormal"><span>When<br />
we choose &#039;7&#039;, &quot;<b>select between 1 &amp; <span class="GramE">5 <span style="font-weight: normal">&quot;</span></span></b> will be displayed!</span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><span>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</span></p>
<p class="MsoNormal"><b><span>/<span class="GramE">/<span></span>demo4.jsp</span></span></b></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>&lt;%@<br />
page <span class="SpellE">contentType</span>=&quot;text/html&quot; %&gt;</span></p>
<p class="MsoNormal"><span>&lt;%@<br />
<span class="SpellE">taglib</span> prefix=&quot;c&quot; <span class="SpellE">uri</span>=&quot;http://java.sun.com/jstl/core<span class="GramE">&quot;<span></span>%</span>&gt;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>&lt;<span class="GramE">html</span>&gt;</span></p>
<p class="MsoNormal"><span>&lt;body<span></span><span></span><span class="SpellE">bgcolor</span>=<span class="SpellE">lightblue</span>&gt;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>&lt;form<span></span>method=<span class="GramE">post<span></span>action</span>=&quot;demo3.jsp&quot;&gt;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>&lt;select name=&quot;combo1&quot;&gt;</span></p>
<p class="MsoNormal"><span><span></span>&lt;option value=&quot;1&quot;&gt;1<span></span>&lt;/option&gt;</span></p>
<p class="MsoNormal"><span><span></span>&lt;option value=&quot;2&quot;&gt;2<span></span>&lt;/option&gt;</span></p>
<p class="MsoNormal"><span><span></span>&lt;option value=&quot;3&quot;&gt;3<span></span>&lt;/option&gt;</span></p>
<p class="MsoNormal"><span><span></span>&lt;option value=&quot;4&quot;&gt;4<span></span>&lt;/option&gt;</span></p>
<p class="MsoNormal"><span><span></span>&lt;option value=&quot;5&quot;&gt;5<span></span>&lt;/option&gt;</span></p>
<p class="MsoNormal"><span><span></span>&lt;option value=&quot;7&quot;&gt;7<span></span>&lt;/option&gt;</span></p>
<p class="MsoNormal"><span><span></span>&lt;/select&gt;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>&lt;<span class="GramE">input<span></span>type</span>=submit&gt;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>&lt;<span class="SpellE">c<span class="GramE">:set</span></span><span class="SpellE">var</span>=&quot;s&quot;<span></span>value<b>=&quot;${param.combo1</b>}&quot;<span></span>/&gt;</span></p>
<p class="MsoNormal"><span>Today<br />
is</span></p>
<p class="MsoNormal"><span>&lt;<span class="SpellE"><span class="GramE">br</span></span>&gt;</span></p>
<p class="MsoNormal"><span>&lt;font<br />
size=24 color=red&gt;</span></p>
<p class="MsoNormal"><b><span>&lt;<span class="SpellE"><span class="GramE">c:</span>choose</span>&gt;</span></b></p>
<p class="MsoNormal"><b><span><span></span>&lt;<span class="SpellE">c<span class="GramE">:when</span></span><span></span>test=&quot;${</span></b><span>s==1}&quot;&gt;Sunday<br />
<b><span></span>&lt;/<span class="SpellE">c:when</span>&gt;</b></span></p>
<p class="MsoNormal"><span><span></span>&lt;<span class="SpellE">c<span class="GramE">:when</span></span><span></span>test=&quot;${s==2}&quot;&gt;Monday&lt;/<span class="SpellE">c:when</span>&gt;</span></p>
<p class="MsoNormal"><span><span></span>&lt;<span class="SpellE">c<span class="GramE">:when</span></span><span></span>test=&quot;${s==3}&quot;&gt;Tuesday&lt;/<span class="SpellE">c:when</span>&gt;</span></p>
<p class="MsoNormal"><span><span></span>&lt;<span class="SpellE">c<span class="GramE">:when</span></span><span></span>test=&quot;${s==4}&quot;&gt;Wednesday&lt;/<span class="SpellE">c:when</span>&gt;</span></p>
<p class="MsoNormal"><span><span></span>&lt;<span class="SpellE">c<span class="GramE">:when</span></span><span></span>test=&quot;${s==5}&quot;&gt;Thursday&lt;/<span class="SpellE">c:when</span>&gt;</span></p>
<p class="MsoNormal"><span></span></p>
<p>&lt;p class=&quot;MsoN</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2011/05/core-tags-in-jstl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Accessing Portlet-specific Objects in JSP Pages</title>
		<link>http://www.javabeat.net/2011/04/accessing-portlet-specific-objects-in-jsp-pages/</link>
		<comments>http://www.javabeat.net/2011/04/accessing-portlet-specific-objects-in-jsp-pages/#comments</comments>
		<pubDate>Sat, 30 Apr 2011 00:18:09 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[JSP]]></category>
		<category><![CDATA[Portlets]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=697</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>This article is based on Portlets in Action, to be published June 2011. I t is being reproduced here by permission from Manning Publications. Manning publishes MEAP (Manning Early Access Program,) ebooks and pbooks. MEAPs are sold exclusively through Manning.com. All print book purchases include an ebook free of charge. When mobile formats become available [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p><em>This article is based on <a href="http://www.manning.com/sarin/">Portlets in Action</a>, to be published June 2011. I t is being reproduced here by permission from <a href="http://www.manning.com">Manning Publications</a>. Manning publishes MEAP (Manning Early Access Program,) ebooks and pbooks. MEAPs are sold exclusively through Manning.com. All print book purchases include an ebook free of charge. When mobile formats become available all customers will be contacted and upgraded. Visit Manning.com for more information.</em></p>
<p><center>Accessing Portlet-specific Objects Using defineObjects Tag</center></p>
<h2>Introduction</h2>
<div style="float: left;"></div>
<p>In a lot of cases, JavaServer Pages (<strong>JSP</strong>s) may rely on <strong>JSP</strong> implicit objects to achieve their functionality. It is perfectly fine to use <strong>JSP</strong> implicit variables in your <strong>JSP</strong> pages, but, on the downside, your <strong>JSP</strong> is dealing with servlet-specific objects (like HttpServletRequest and HttpSession) and not portlet-specific objects (like RenderRequest and PortletSession).</p>
<p>If we add an attribute to RenderRequest, it’s mirrored by HttpServletRequest and vice versa. The same applies to HttpSession and PortletSession. So what difference does it make if we use portlet-specific objects in <strong>JSP</strong>s? Subtle differences between servlet and portlet API can answer this question. For instance, in your <strong>JSP</strong> page, you can’t use HttpServletResponse to create a portlet URL (only a RenderResponse object provides methods to create portlet URLs). HttpServletRequest can’t provide the information about the portlet mode and the window state (PortletRequest provides methods to obtain the portlet mode and the window state). This is like rain and freezing rain—both are forms of precipitation with the only difference in what happens when raindrops hit the ground.</p>
<p>In general, your <strong>JSP</strong> pages will use a combination of portlet and servlet objects to generate content. For instance, if you want to set the expiration time for the content in the <strong>JSP</strong> page, you will use the RenderResponse portlet object. If you need to obtain the value of an APPLICATION_SCOPE portlet session attribute, you may prefer to use session (which refers to HttpSession object) or sessionScope (which is a java.util.Map of session attributes stored in HttpSession object) for a <strong>JSP</strong> implicit object to obtain its value.</p>
<h3><span style="color: red;">NOTE</span></h3>
<p><em><strong>JSP</strong>s included by <strong>portlets</strong> have access to <strong>JSP</strong> implicit objects because portlet application is also a web application.</em></p>
<p>The name <em>defineObjects</em> gives the impression that it can be used by <strong>JSP</strong> developers to define custom objects in their <strong>JSP</strong> pages, but that’s not the case. The defineObjects tag of portlet tag library provides <strong>JSP</strong>s with access to portlet objects like RenderRequest, RenderResponse, PortletSession, and so on. Table 1 lists the scripting variables (and their type) that are available to <strong>JSP</strong> pages that use defineObjects tag.</p>
<p><a href="http://www.javabeat.net/wp-content/uploads/2011/04/125.jpg"><img class="aligncenter size-medium wp-image-1234" title="1" src="http://www.javabeat.net/wp-content/uploads/2011/04/125-294x300.jpg" alt="" width="294" height="300" /></a>Table 1 shows the scripting variables defined by the defineObject tag. As you can see, defineObjects provides <strong>JSP</strong> pages with all Portlet 2.0 API objects they’ll ever need to use portlet-specific features. In <strong>JSP</strong> pages, you’ll usually use a combination of <strong>JSP</strong> implicit objects and the implicit objects made available by defineObjects tag. You&#8217;ll probably never use actionRequest, actionResponse, eventRequest, and eventResponse objects in your <strong>JSP</strong> pages because the portlet container ignores the content written out to the response in action and event processing phases.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<h3><span style="color: red;">NOTE</span></h3>
<p><em>defineObjects tag doesn’t define any attributes.</em></p>
<p>The sample Book Catalog portlet in this article uses scripting variables introduced by defineObjects tag to show the debugging information, as shown earlier in figure 1.</p>
<p>Listing 1 shows debug.jsp page and is included by all JSP pages in the Book Catalog portlet. The debug.jsp page prints the information about the portlet mode, the window state, the value of myaction attribute from request, the content expiration time, and so on, most of which is obtained using scripting variables introduced by defineObjects tag.</p>
<p><strong><span style="color: red;">Listing 1 debug.jsp—Using variables introduced by defineObjects tag</span></strong></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
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;%@ taglib prefix=&quot;portlet&quot; 						#1
		uri=&quot;http://java.sun.com/portlet_2_0&quot;%&gt; 			#1
	&lt;%@ page contentType=&quot;text/html&quot; isELIgnored=&quot;false&quot;
		import=&quot;javax.portlet.PortletSession&quot;%&gt;
	&lt;portlet:defineObjects /&gt; 						#2
	....
	Value of myaction request attribute:
		${requestScope.myaction} 					#3
	Portlet mode of request:
		&lt;%=renderRequest.getPortletMode()%&gt; 				#4
	Window state of request:
		&lt;%=renderRequest.getWindowState()%&gt; 				#5
	Content Expiration time:
		&lt;%=renderResponse.getCacheControl().getExpirationTime()%&gt; 	#6
	seconds
	uploadFolder init parameter value:
		&lt;%=portletConfig.getInitParameter(&quot;uploadFolder&quot;)%&gt; 		#7
	myaction attribute value in PortletSession:
		${portletSessionScope.myaction} 				#8
	Search criteria stored in PortletSession:
		Book name –
		&lt;%=portletSession.getAttribute(&quot;bookNameSearchField&quot;, 		#9
		PortletSession.APPLICATION_SCOPE)%&gt; 				#9
		Author name –
		&lt;%=session.getAttribute(&quot;authorNameSearchField&quot;)%&gt; 		#10
&nbsp;
		#1 Declare portlet tab library
		#2 defineObjects tag
		#3 myaction HttpRequest attribute
		#4 Portlet mode from RenderRequest
		#5 Window state from RenderRequest
		#6 Cache expiration time from RenderResponse
		#7 uploadFolder portlet initialization parameter
		#8 myaction PortletSession attribute
		#9 bookNameSearchField PortletSession attribute
		#10 authorNameSearchField HttpSession attribute</pre></td></tr></table></div>

<p>At #1, the JSP page declares the portlet tag library using the taglib directory. The value of the uri attribute is <a href="http://java.sun.com/portlet_2_0" target="_blank">http://java.sun.com/portlet_2_0</a> if you want to use Portlet 2.0 tag library. If you are using Portlet 1.0 tag library, specify the value of uri as <a href="http://java.sun.com/portlet" target="_blank">http://java.sun.com/portlet</a>. The defineObjects tag in Portlet 2.0 introduced additional variables like <strong>portletSessionScope</strong>, <strong>portletSession</strong>, and so on, which makes it easy to develop portlets using JSP as the view technology. At #2, the defineObjects tag is used to introduce scripting variables in the JSP page. At #3, the requestScope JSP implicit variable is used to obtain the value of the myaction attribute. At #4, the renderRequest variable is used to obtain the current portlet mode. At #5, the renderRequest variable is used to obtain the window state information. At #6, the renderResponse variable is used to obtain CacheControl object, which, in turn, is used to obtain the expiration time for the generated content. At #7, the portletConfig object is used to obtain the uploadFolder portlet initialization parameter. At #8, the <strong>portletSessionScope</strong> variable is used to obtain the value of the myaction attribute from PortletSession. At #9, the portletSession variable is used to obtain the value of the bookNameSearchField attribute from APPLICATION_SCOPE of PortletSession. At #10, the session <strong>JSP</strong> implicit variable is used to obtain the value of the authorNameSearchField attribute from HttpSession. We see here that using the session <strong>JSP</strong> implicit variable makes it easy to retrieve the APPLICATION_SCOPE attribute stored in PortletSession.</p>
<p>Listing 1 shows that we’ll usually use <strong>JSP</strong> implicit variables and variables introduced by the defineObjects tag to create <strong>JSP</strong> pages. If you browse through the pages of the Book Catalog portlet, the debugging information will change to reflect the current value of various attributes displayed by the debug.jsp page.</p>
<h2>Summary</h2>
<p>In this article, we saw how the portlet tag library tags can be used to simplify development of <strong>JSP</strong> pages used by portlets. Specifically, we learned how to use <strong>JSP</strong> implicit variables and variables introduced by the defineObjects tag to create <strong>JSP</strong> pages.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2011/04/accessing-portlet-specific-objects-in-jsp-pages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JSTL Function in JSP 2.0</title>
		<link>http://www.javabeat.net/2009/03/jstl-function-in-jsp-2-0/</link>
		<comments>http://www.javabeat.net/2009/03/jstl-function-in-jsp-2-0/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 04:40:16 +0000</pubDate>
		<dc:creator>JavaBeat</dc:creator>
				<category><![CDATA[JSP]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/examples/?p=493</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>In JSP 2.0 we can perform string operations in JSP without using any java code inside scriptlets. This is possible with the latest release of JSTL 1.1. The new library called Functions with prefix as fn allows us to perform string operations in JSP 2.0. The following example explains all the string operation which we [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p>
	In <b>JSP 2.0</b> we can perform string operations in JSP without using any java code inside scriptlets. This is possible with the latest release of <b>JSTL 1.1</b>. The new library called <b>Functions</b> with prefix as <b>fn</b> allows us to perform string operations in <b>JSP 2.0</b>.
</p>
<p>
	The following example explains all the string operation which we can perform with the new <b>fn</b> tags.<br />
<b>Note</b>:</p>
<ul>
<li>You will need the following files to run this example :</li>
<li><b>jstl.jar and standard.jar</b> inside /WEB-INF/lib </li>
<li><b>fn.tld, c.tld</b> inside any location under any lcation under WEB-INF</li>
<h2>JSP 2.0 Function : Example</h2>
<p>
1) File Name : <b>firstPage.jsp</b></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
25
26
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;%@ page contentType=&quot;text/html&quot; %&gt;
&lt;html&gt;
&lt;body&gt;
	&lt;form name=&quot;myForm&quot; method=&quot;post&quot; action=&quot;functionsUsage.jsp&quot;&gt;
		Select an operation and click the button&lt;br /&gt;&lt;br /&gt;
		&lt;input type=&quot;radio&quot; name=&quot;radioBtnGroup&quot; value=&quot;uCaseOp&quot; /&gt;Convert a string to upper Case&lt;br /&gt;
		&lt;input type=&quot;radio&quot; name=&quot;radioBtnGroup&quot; value=&quot;lCaseOp&quot; /&gt;Convert a string to lower Case&lt;br /&gt;
		&lt;input type=&quot;radio&quot; name=&quot;radioBtnGroup&quot; value=&quot;subStrOp&quot; /&gt;Get a substring of a string&lt;br /&gt;
		&lt;input type=&quot;radio&quot; name=&quot;radioBtnGroup&quot; value=&quot;subStrAfterOp&quot; /&gt;Get substring after&lt;br /&gt;
		&lt;input type=&quot;radio&quot; name=&quot;radioBtnGroup&quot; value=&quot;subStrBeforeOp&quot; /&gt;Get substring before&lt;br /&gt;
		&lt;input type=&quot;radio&quot; name=&quot;radioBtnGroup&quot; value=&quot;trimOp&quot; /&gt;Trim the string&lt;br /&gt;
		&lt;input type=&quot;radio&quot; name=&quot;radioBtnGroup&quot; value=&quot;replaceOp&quot; /&gt;Replaces characters in a string&lt;br /&gt;
		&lt;input type=&quot;radio&quot; name=&quot;radioBtnGroup&quot; value=&quot;splitOp&quot; /&gt;Split a string&lt;br /&gt;
		&lt;input type=&quot;radio&quot; name=&quot;radioBtnGroup&quot; value=&quot;joinOp&quot; /&gt;Join a string after it has been split&lt;br /&gt;
		&lt;input type=&quot;radio&quot; name=&quot;radioBtnGroup&quot; value=&quot;escapeXml&quot; /&gt;Escapes XML characters in a string&lt;br /&gt;
		&lt;input type=&quot;radio&quot; name=&quot;radioBtnGroup&quot; value=&quot;indexOf&quot; /&gt;Find start index of a substring in a string&lt;br /&gt;
		&lt;input type=&quot;radio&quot; name=&quot;radioBtnGroup&quot; value=&quot;startsWithOp&quot; /&gt;Check if the string starts with a particular substring&lt;br /&gt;
		&lt;input type=&quot;radio&quot; name=&quot;radioBtnGroup&quot; value=&quot;endsWithOp&quot; /&gt;Check if the string end with a particular substring&lt;br /&gt;
		&lt;input type=&quot;radio&quot; name=&quot;radioBtnGroup&quot; value=&quot;containsOp&quot; /&gt;Check if the string contains a particular substring(Case Sensitive)&lt;br /&gt;
		&lt;input type=&quot;radio&quot; name=&quot;radioBtnGroup&quot; value=&quot;containsIgnoreCaseOp&quot; /&gt;Check if the string contains a particular substring(Case In-sensitive)&lt;br /&gt;
		&lt;input type=&quot;radio&quot; name=&quot;radioBtnGroup&quot; value=&quot;lengthOp&quot; /&gt;Length of a String&lt;br /&gt;
		&lt;br /&gt;
		&lt;input type=&quot;Submit&quot; name=&quot;submitBtn&quot; value=&quot;Click&quot; /&gt;
	&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>2) File Name : <b>functionsUsage.jsp</b></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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;%@ page contentType=&quot;text/html&quot; %&gt;
&lt;%@ taglib prefix=&quot;c&quot; uri=&quot;http://java.sun.com/jsp/jstl/core&quot; %&gt;
&lt;%@ taglib prefix=&quot;fn&quot; uri=&quot;http://java.sun.com/jsp/jstl/functions&quot; %&gt;
&lt;html&gt;
	&lt;body&gt;
	&lt;c:choose&gt;
		&lt;c:when test=&quot;${param.radioBtnGroup=='uCaseOp'}&quot;&gt;
			Source String : california
			&lt;br /&gt;
			UpperCase	  : ${fn:toUpperCase('california')}
		&lt;/c:when&gt;
		&lt;c:when test=&quot;${param.radioBtnGroup=='lCaseOp'}&quot;&gt;
			Source String : CALIFORNIA
			&lt;br /&gt;
			Lowercase	  : ${fn:toLowerCase('CALIFORNIA')}
		&lt;/c:when&gt;
		&lt;c:when test=&quot;${param.radioBtnGroup=='subStrOp'}&quot;&gt;
			Source String : California
			&lt;br /&gt;
			Substring	  : ${fn:substring('California',4,7)}
		&lt;/c:when&gt;
		&lt;c:when test=&quot;${param.radioBtnGroup=='subStrAfterOp'}&quot;&gt;
			Source String : California
			&lt;br /&gt;
			Substring After	&quot;Cali&quot; : ${fn:substringAfter('California','Cali')}
		&lt;/c:when&gt;
		&lt;c:when test=&quot;${param.radioBtnGroup=='subStrBeforeOp'}&quot;&gt;
			Source String : California
			&lt;br /&gt;
			Substring Before &quot;fornia&quot; : ${fn:substringBefore('California','fornia')}
		&lt;/c:when&gt;
		&lt;c:when test=&quot;${param.radioBtnGroup=='trimOp'}&quot;&gt;
			Source String : California
			&lt;br /&gt;
			Trim the string &quot; California &quot; : ${fn:trim(' California ')}
		&lt;/c:when&gt;
		&lt;c:when test=&quot;${param.radioBtnGroup=='replaceOp'}&quot;&gt;
			Source String : California
			&lt;br /&gt;
			Replace : ${fn:replace('California','a','A')}
		&lt;/c:when&gt;
		&lt;c:when test=&quot;${param.radioBtnGroup=='splitOp'}&quot;&gt;
			Source String : Cali;fornia
			&lt;br /&gt;
			Split Separator : &quot;;&quot;
			&lt;br /&gt;
			After Split an array is created with two items:
			&lt;br /&gt;
			Item at index 0 : ${fn:split('Cali;fornia ',';')[0]}
			&lt;br /&gt;
			Item at index 1 : ${fn:split('Cali;fornia ',';')[1]}
		&lt;/c:when&gt;
		&lt;c:when test=&quot;${param.radioBtnGroup=='joinOp'}&quot;&gt;
			Source String : Cali;fornia
			&lt;br /&gt;
			Split Separator : &quot;;&quot;
			&lt;br /&gt;
			Join Separator : &quot;|&quot;
			&lt;br /&gt;
			Join :
			&lt;c:set var=&quot;a1&quot; value=&quot;${fn:split('Cali;fornia', ';')}&quot;  /&gt;
			&lt;c:out value=&quot;${fn:join(a1, '|')}&quot; /&gt;
		&lt;/c:when&gt;
		&lt;c:when test=&quot;${param.radioBtnGroup=='escapeXml'}&quot;&gt;
			${fn:escapeXml('&lt;city&gt;California&lt;/city&gt;')}
		&lt;/c:when&gt;
		&lt;c:when test=&quot;${param.radioBtnGroup=='indexOf'}&quot;&gt;
			Source String : California
			&lt;br /&gt;
			Index Of &quot;for&quot; : ${fn:indexOf('California','for')}
			&lt;br /&gt;
		&lt;/c:when&gt;
		&lt;c:when test=&quot;${param.radioBtnGroup=='startsWithOp'}&quot;&gt;
			Source String : California
			&lt;br /&gt;
			Starts With &quot;Cal&quot; : ${fn:startsWith('California','Cal')}
		&lt;/c:when&gt;
		&lt;c:when test=&quot;${param.radioBtnGroup=='endsWithOp'}&quot;&gt;
			Source String : California
			&lt;br /&gt;
			Ends With &quot;nia&quot; : ${fn:endsWith('California','nia')}
		&lt;/c:when&gt;
		&lt;c:when test=&quot;${param.radioBtnGroup=='containsOp'}&quot;&gt;
			Source String : California
			&lt;br /&gt;
			Contains &quot;FOR&quot; : ${fn:contains('California','FOR')}
		&lt;/c:when&gt;
		&lt;c:when test=&quot;${param.radioBtnGroup=='containsIgnoreCaseOp'}&quot;&gt;
			Source String : California
			&lt;br /&gt;
			Contains IgnoreCase &quot;FOR&quot; : ${fn:containsIgnoreCase('California','FOR')}
		&lt;/c:when&gt;
		&lt;c:when test=&quot;${param.radioBtnGroup=='lengthOp'}&quot;&gt;
			Source String : California
			&lt;br /&gt;
			Length of the string : ${fn:length('California')}
		&lt;/c:when&gt;
		&lt;c:otherwise&gt;
			Please make a selection to perform an operation
		&lt;/c:otherwise&gt;
	&lt;/c:choose&gt;
&nbsp;
	&lt;br /&gt;&lt;br /&gt;
	&lt;a href=&quot;home.jsp&quot;&gt;&lt;&lt; Back&lt;/a&gt;
	&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>3) Output</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p>
Source String : Cali;fornia <br />
Split Separator : &#8220;;&#8221; <br />
Join Separator : &#8220;|&#8221; <br />
Join : Cali|fornia </p>
<p><< Back
</p>
<h2>JSP 2.0 Function : Explanation</h2>
<p>
In this example we can see the usage of the string functions defined as part of the new <b>JSTL 1.1</b> tag library.<br />
The functions are part of the new <b>Function</b> library and they needs to be prefixed with <b>fn</b> as we can see in the examples. This reduces lot of development effort and our jsps look a lot cleaner as we dont have to mix java code inside jsp.
</p>
<p>
The Functions library includes the following string functions : <b><i>toUpperCase, toLowerCase, substring, substringAfter, substringBefore, trim, replace, split, join, indexOf, startsWith, endsWith, contains, containsIgnoreCase and length</i></b></p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2009/03/jstl-function-in-jsp-2-0/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dynamic Attributes in Tag File in JSP 2.0</title>
		<link>http://www.javabeat.net/2009/02/dynamic-attributes-in-tag-file-in-jsp-2-0/</link>
		<comments>http://www.javabeat.net/2009/02/dynamic-attributes-in-tag-file-in-jsp-2-0/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 04:39:21 +0000</pubDate>
		<dc:creator>JavaBeat</dc:creator>
				<category><![CDATA[JSP]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/examples/?p=491</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>As we know that we can develop custom tag library as a simple tag file in JSP 2.0 and these tag files can accept attributes from the invoking JSP page. But one drawback of this approach is that we need to declare all the attributes in the tag file. JSP 2.0 provides a feature called [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p>
As we know that we can develop custom tag library as a simple <b><a href="http://www.javabeat.net/tips/175-custom-tag-libraries-and-tag-files-in-jsp-20.html">tag file in JSP 2.0</a></b> and these tag files can accept attributes from the invoking JSP page. But one drawback of this approach is that we need to declare all the attributes in the tag file. <b>JSP 2.0</b> provides a feature called dynamic attributes by using which we need not<br />
declare the attributes in the tag file using the <b>attribute</b> directive.
</p>
<p></p>
<p>
1) File Name : <b>firstPage.jsp</b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;%@ page contentType=&quot;text/html&quot; %&gt;
&lt;%@ taglib prefix=&quot;my&quot; tagdir=&quot;/WEB-INF/tags/mytags&quot; %&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Headers&lt;/title&gt;
&lt;/head&gt;
&lt;body bgcolor=&quot;white&quot;&gt;
	&lt;my:person Age=&quot;28&quot; EmployeeId=&quot;74852&quot; Name=&quot;Bruce Wayne&quot;  /&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>2) File Name : <b>person.tag</b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;%@ tag body-content=&quot;empty&quot; dynamic-attributes=&quot;dynattrs&quot; %&gt;
&lt;%@ taglib prefix=&quot;c&quot; uri=&quot;http://java.sun.com/jsp/jstl/core&quot; %&gt;
&nbsp;
&lt;table border=&quot;1&quot; width=&quot;30%&quot; height=&quot;20%&quot; style=&quot;background-color:#EFEFEF&quot;&gt;
	&lt;c:forEach items=&quot;${dynattrs}&quot; var=&quot;a&quot;&gt;
	&lt;tr&gt;
		&lt;td&gt;${a.key}&lt;/td&gt;
		&lt;td&gt;${a.value}&lt;/td&gt;
	&lt;/tr&gt;
	&lt;/c:forEach&gt;
&lt;/table&gt;</pre></td></tr></table></div>

<p>3) <b>Output</b></p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<table border="1" width="30%" style="background-color:#EFEFEF">
<tr>
<td>EmployeeId</td>
<td>74852</td>
</tr>
<tr>
<td>Name</td>
<td>Bruce Wayne</td>
</tr>
<tr>
<td>Age</td>
<td>28</td>
</tr>
</table>
<p><b>Explantion:</b></p>
<p>
In the file <b>firstPage.jsp</b> I invoke a custom tag named <b>person</b> with three attributes : <b>employee id, age and name</b>.</p>
<p>The file <b>person.tag</b> holds the code to handle the <b>person</b> tag invocation. In this file I use the tag directive to declare a page scope attribute named <b>dynattrs</b>. This attribute is a <b>Map</b> of all the attributes and attribute values passed from the JSP page tag invocation. Next, I iterate through each item of <b>dynattrs</b> using c:forEach jstl tag. The property: <b>key</b> returns the map key and the property : <b>value</b> returns the key&#8217;s value. I use Expression language syntax <b>${}</b> to display each key and value stored in the map.
</p>
<p><b>JSP 2.0 Custom Tags Reference</b></p>
<ul>
<li><a href="http://www.javabeat.net/tips/175-custom-tag-libraries-and-tag-files-in-jsp-20.html">Custom Tag Libraries and Tag Files in JSP 2.0</a></li>
<li><a href="http://www.javabeat.net/tips/176-custom-tags-in-jsp-20.html">Custom Tags in JSP 2.0</a></li>
<li><a href="http://www.javabeat.net/tips/177-variable-directive-in-jsp-20-custom-tags.html">Variable Directive in JSP 2.0 Custom Tags</a></li>
</ul>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2009/02/dynamic-attributes-in-tag-file-in-jsp-2-0/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Variable Directive in JSP 2.0 Custom Tags</title>
		<link>http://www.javabeat.net/2009/02/variable-directive-in-jsp-2-0-custom-tags/</link>
		<comments>http://www.javabeat.net/2009/02/variable-directive-in-jsp-2-0-custom-tags/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 04:49:36 +0000</pubDate>
		<dc:creator>JavaBeat</dc:creator>
				<category><![CDATA[JSP]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/examples/?p=519</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>This tips explains how to use the variable directive in the custom tags in JSP 2.0. There is time when JSP page needs to access the variable declared inside the Tag files. In the previous version we have to extend the tag library to declare the variables and need the special handling for those variables. [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p>This tips explains how to use the <b>variable directive</b> in the custom tags in JSP 2.0. There is time when JSP page needs to<br />
access the variable declared inside the Tag files. In the previous version we have to extend the tag library to declare the variables<br />
and need the special handling for those variables. In <b>JSP 2.0</b>, it is done very easily using the <b>variable directive</b>. Syntax for the<br />
variable directive is as follows:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">	&lt;%@ variable (attribute=&quot;value&quot;)* %&gt;</pre></td></tr></table></div>

<p>or</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">	&lt;@ variable attribute1=&quot;value1&quot; attribute2=&quot;value2&quot; ... %&gt;</pre></td></tr></table></div>

<p>The following are the list of attributes in variable directive:</p>
<ul>
<li><i>name-given</i></li>
<li><i>name-from-attribute</i></li>
<li><i>alias</i></li>
<li><i>variable-class</i></li>
<li><i>declare</i></li>
<li><i>scope</i></li>
<li><i>description</i></li>
</ul>
<p>Look into the following example:</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p><b>index.jsp</b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">	&lt;%@ taglib prefix=&quot;print&quot; tagdir=&quot;/WEB-INF/tags/&quot; %&gt;
	&lt;html&gt;
		&lt;body bgcolor=&quot;white&quot;&gt;
			&lt;print:varTag&gt;
				${testValue}
			&lt;/print:varTag&gt;
		&lt;/body&gt;
	&lt;/html&gt;</pre></td></tr></table></div>

<p><b>varTag.jsp</b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">	&lt;%@ variable name-given=&quot;testValue&quot; %&gt;
	&lt;%
		jspContext.setAttribute(&quot;testValue&quot;, &quot;testValue&quot;);
	%&gt;
	&lt;jsp:doBody/&gt;</pre></td></tr></table></div>

<p>In the above example it declares one simple variable named <i>testValue</i> and it is access from the JSP page. This example is only very simple and the purpose is to explain how the variable directive is working. Like this you can declare asmany variables in the Tag Files and can be used in the JSP file. <jsp:doBody/> at the end of tag file is important to execute the tag body.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2009/02/variable-directive-in-jsp-2-0-custom-tags/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Tags in JSP 2.0</title>
		<link>http://www.javabeat.net/2009/02/custom-tags-in-jsp-2-0/</link>
		<comments>http://www.javabeat.net/2009/02/custom-tags-in-jsp-2-0/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 04:49:01 +0000</pubDate>
		<dc:creator>JavaBeat</dc:creator>
				<category><![CDATA[JSP]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/examples/?p=517</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Tag Files in JSP 2.0 This tips explains about what are the advantages in the Custom Tags in JSP 2.0. It also compares it with the previous JSP versions. Lets look into the tips for more detail. Developing custom tags in the previous JSP versions are tedious and it is considered as one of the [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><h2>Tag Files in JSP 2.0</h2>
<p>This tips explains about what are the advantages in the Custom Tags in JSP 2.0. It also compares it with the previous JSP versions.<br />
Lets look into the tips for more detail.</p>
<p>Developing custom tags in the previous JSP versions are tedious and it is considered as one of the complex task for the JSP developers. Because inorderto write a simple custom tag you have to learn many things and should have good knowledge on Java also. Apart from that you have to use Tag APIs to create a complete tag library. Any small mistake will cause the error and tag files will not work. To make the things easy for the JSP developers, JSP 2.0 has the advanced features for creating JSP custom tag libraries.</p>
<p>The following are the mandatory for writing the custom tags in previous versions:</p>
<ul>
<li>Writing and compiling a tag handler.</li>
<li>Defining the tag that is associated with the tag handler.</li>
<li>Creating the TLD(Taglib Descriptor) files.</li>
</ul>
<h2>What is Tag Files?</h2>
<p>JSP 2.0 has introduced the concept called tag files, which are nothing but the simple files works like a JSP file. They define all the<br />
functionalities required for a custome tag. You are no longer required to write the Java file and compile it. These tag files are compiled dynamically by the JSP container. Even though, it is simple file, JSP container will convert these files into a Tag Library. But developers need not worry about them.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p>Tag files just work like an JSP pages, it has the following implicit objects:</p>
<ul>
<li><i>request -> 	javax.servlet.http.HttpServletRequest</i></li>
<li><i>response ->	javax.servlet.http.HttpServletResponse</i></li>
<li><i>out ->	javax.servlet.jsp.JspWriter</i></li>
<li><i>session -> 	javax.servlet.http.HttpSession</i></li>
<li><i>application ->	javax.servlet.ServletContext</i></li>
<li><i>config ->	javax.servlet.ServletConfig</i></li>
<li><i>jspContext ->	javax.servlet.jsp.JspContext</i></li>
</ul>
<p>All the abobe objects are available in the normal JSP files also.</p>
<p>All the tag files must be put under the folder <b><i>WEB-INF/tags</i></b> or you can create the sub directory under it. The directory name must be specified while importing the tags in JSP file as follows:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;%@ taglib prefix=&quot;tagFiles&quot;
  tagdir=&quot;/WEB-INF/tags&quot; %&gt;</pre></td></tr></table></div>

<h2>Tag Files Example</h2>
<p> This tips explains only the very basic points about the new features in custom tags and Tag Files. You can find <a href="http://www.javabeat.net/tips/175-custom-tag-libraries-and-tag-files-in-jsp-20.html">simple example on writing the custome tags in JSP 2.0</a>.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2009/02/custom-tags-in-jsp-2-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Tag Libraries and Tag Files in JSP 2.0</title>
		<link>http://www.javabeat.net/2009/02/custom-tag-libraries-and-tag-files-in-jsp-2-0/</link>
		<comments>http://www.javabeat.net/2009/02/custom-tag-libraries-and-tag-files-in-jsp-2-0/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 04:38:35 +0000</pubDate>
		<dc:creator>JavaBeat</dc:creator>
				<category><![CDATA[JSP]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/examples/?p=489</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>With previous versions of JSP developing custom tag libraries was possible only by writing Java classes. As a result knowledge of Java was a must. JSP 2.0 introduces a new way of developing custom tag library using plain JSP. This enables JSP developers, who dont know Java, to develop custom tag libraries as Tag files. [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p>
With previous versions of <b>JSP</b> developing custom tag libraries was possible only by writing <b>Java</b> classes. As a result knowledge of Java was a must. JSP 2.0 introduces a new way of developing custom tag library<br />
using plain JSP. This enables JSP developers, who dont know Java, to develop custom tag libraries as <b>Tag files</b>. JSP 2.0 also provided added features of passing parameters to tag files. I will demonstrate this in the following examples.
</p>
<p></p>
<p>
1) File Name : <b>firstPage.jsp</b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;%@ page contentType=&quot;text/html&quot; %&gt;
&lt;%@ taglib prefix=&quot;my&quot; tagdir=&quot;/WEB-INF/tags/myCustomTags&quot; %&gt;
&lt;html&gt;
	&lt;body bgcolor=&quot;white&quot;&gt;
		Random Number : &lt;my:generateRandomNum /&gt;
	&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>2) File Name : <b>generateRandomNum.tag</b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;%@ tag body-content=&quot;empty&quot; %&gt;
&lt;%
	out.println(java.lang.Math.random());
%&gt;</pre></td></tr></table></div>

<p>3) <b>Output</b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">Random Number : 0.029871659130147776</pre></td></tr></table></div>

<h2>Explantion:</h2>
<p>
In my first example I use a tag file to generate <b>random numbers</b>. I will first explain the code in <b>generateRandomNum.tag</b> file. This is just a simple file with a <b>.tag</b> extension and a <b>tag</b> directive. In this file I write the logic to generate random numbers using the <b>java.lang.Math</b> class. Once this file is ready place the file under any location below WEB-INF directory. I have placed it inside /WEB-INF/tags/myCustomTags directory.</p>
<p>Now in the <b>firstPage.jsp</b> I use a <b>taglib</b> directive. In the taglib directive I set the value for two attributes : <b>prefix and tagdir</b>. The prefix sets a prefix to invoke the custom tag and the tagdir attribute<br />
tell the container that the tag file is placed at the location specified. Next I invoke the tag file simply by using<br />
the prefix and the name of the tag file, without the <b>.tag extension</b>
</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p>4) File Name : <b>secondPage.jsp</b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;%@ page contentType=&quot;text/html&quot; %&gt;
&lt;%@ taglib prefix=&quot;my&quot; tagdir=&quot;/WEB-INF/tags/myCustomTags&quot; %&gt;
&lt;html&gt;
	&lt;body bgcolor=&quot;white&quot;&gt;
		Sum of two numbers : &lt;my:addNumbers firstNum=&quot;10&quot; secondNum=&quot;20&quot; /&gt;
	&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>5) File Name : <b>addNumbers.tag</b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;%@ tag body-content=&quot;empty&quot; %&gt;
&lt;%@ attribute name=&quot;firstNum&quot; required=&quot;true&quot;%&gt;
&lt;%@ attribute name=&quot;secondNum&quot; required=&quot;true&quot;%&gt;
&nbsp;
${firstNum + secondNum}</pre></td></tr></table></div>

<p>6) <b>Output</b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">Sum of two numbers : 30</pre></td></tr></table></div>

</p>
<h2>Explantion:</h2>
<p>
In this second example I explain the usage of passing <b>attributes</b> to tag files. In the file <b>addNumbers.tag</b> I have used a directive called <b>attribute</b>. This is basically used to tell the web container that this tag file expects an attribute and whether the attribute is mandatory or optional.<br />
We should use the attribute directive for each attribute passed from the invoking jsp file. I declare two attributes and use them to perform an add operation using <b>Expressions Langauge (EL)</b>.</p>
<p>In the file <b>secondPage.jsp</b> I invoke the tag and pass attributes with some values. The values will be received<br />
by the attributes declared in the tag file and will be used to perform the addition.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2009/02/custom-tag-libraries-and-tag-files-in-jsp-2-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Error Pages in JSP 2.0</title>
		<link>http://www.javabeat.net/2009/02/error-pages-in-jsp-2-0/</link>
		<comments>http://www.javabeat.net/2009/02/error-pages-in-jsp-2-0/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 04:38:04 +0000</pubDate>
		<dc:creator>JavaBeat</dc:creator>
				<category><![CDATA[JSP]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/examples/?p=487</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>We can configure error pages in jsp and servlets to direct the control to a custom error page, showing a friendly error message to the user when an exception is thrown in the page. But tracking or logging the exception information is not very easy in JSP 1.2. JSP 2.0 fixes this problem by switching [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p>We can configure <b>error pages</b> in jsp and servlets to direct the control to a custom error page, showing<br />
a friendly error message to the user when an exception is thrown in the page. But tracking or logging the exception information is not very easy in JSP 1.2.</p>
<p>JSP 2.0 fixes this problem by switching to the servlet specification: <b>javax.servlet.error.exception</b>. In addition, a new property of the implicit EL <b>pageContext</b> variable, named <b>errorData</b>, exposes other information about the problem. The <b>errorData</b> property is an instance of the <b>javax.servlet.jsp.ErrorData</b> class that can be used as a bean with the following properties:</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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;table border=&quot;1&quot; width=&quot;55%&quot; style=&quot;background-color:#EFEFEF&quot;&gt;
	&lt;tr align=&quot;center&quot;&gt;
		&lt;td width=&quot;10%&quot;&gt;&lt;b&gt;Property&lt;/b&gt;&lt;/td&gt;
		&lt;td width=&quot;12%&quot;&gt;&lt;b&gt;Java Type&lt;/b&gt;&lt;/td&gt;
		&lt;td&gt;&lt;b&gt;Description&lt;/b&gt;&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr align=&quot;left&quot;&gt;
		&lt;td&gt;requestURI&lt;/td&gt;
		&lt;td&gt;String&lt;/td&gt;
		&lt;td&gt;The URI for the request that failed.&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td&gt;servletName&lt;/td&gt;
		&lt;td&gt;String&lt;/td&gt;
		&lt;td&gt;The name of the servlet or JSP page that failed.&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td&gt;statusCode&lt;/td&gt;
		&lt;td&gt;int&lt;/td&gt;
		&lt;td&gt;The failure status code. &lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td&gt;throwable&lt;/td&gt;
		&lt;td&gt;Throwable&lt;/td&gt;
		&lt;td&gt;The exception that caused the error page to be invoked.&lt;/td&gt;
	&lt;/tr&gt;
&lt;table&gt;
&lt;/p&gt;
&nbsp;
&lt;p&gt;
1) File Name : &lt;b&gt;firstPage.jsp&lt;/b&gt;
&lt;pre lang=&quot;LANGUAGE&quot; line=&quot;1&quot;&gt;
&lt;%@page errorPage=&quot;/jsp/errorpage.jsp&quot; contentType=&quot;text/html&quot; %&gt;
&lt;html&gt;
&lt;head&gt;
	&lt;title&gt;Error Pages in JSP 2.0&lt;/title&gt;
&lt;/head&gt;
	&lt;body&gt;
	&lt;%
		String s = null;
		out.println(s.trim());
	%&gt;
	&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>2) File Name : <b>errorpage.jsp</b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;%@page isErrorPage=&quot;true&quot; contentType=&quot;text/html&quot; %&gt;
&lt;html&gt;
	&lt;body&gt;
		Request that failed: ${pageContext.errorData.requestURI}
		&lt;br /&gt;
		Status code: ${pageContext.errorData.statusCode}
		&lt;br /&gt;
		Exception: ${pageContext.errorData.throwable}
		&lt;br /&gt;
		${pageContext.errorData.servletName}
	&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>3) <b>Output</b></p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">Request that failed: /TestWebApp/jsp/firstPage.jsp
Status code: 500
Exception: java.lang.NullPointerException
jsp</pre></td></tr></table></div>

</p>
<h2>Explantion:</h2>
<p>
	In the first page I declare a null string and I call a function on it. The JSP engine will encounter faulty code and will throw a <b>NullPointerException</b>. As I have configured an error page in the page directive the control is taken to the <b>errorpage.jsp</b>.</p>
<p>	In the error page I use properties of <b>errorData</b> to display useful information about the exception. This information is useful for the developer to track down the problem quickly and efficiently as he will know<br />
	exactly which page threw the exception and what was the type of exception.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2009/02/error-pages-in-jsp-2-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ternary Operator in JSP 2.0 Expression Language(EL)</title>
		<link>http://www.javabeat.net/2009/02/ternary-operator-in-jsp-2-0-expression-languageel/</link>
		<comments>http://www.javabeat.net/2009/02/ternary-operator-in-jsp-2-0-expression-languageel/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 04:36:39 +0000</pubDate>
		<dc:creator>JavaBeat</dc:creator>
				<category><![CDATA[JSP]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/examples/?p=485</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>A very common need in a JSP page is to include a piece of template text only if a certain condition is true. With JSP 1.2 and JSTL 1.1, this is typically done using a block, but that&#8217;s a very verbose solution. JSP 2.0 adds a new conditional operator to the Expression Language(EL) to deal [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p>
A very common need in a <b>JSP</b> page is to include a piece of template text only if a certain condition is true.<br />
With <b>JSP 1.2</b> and <b>JSTL 1.1</b>, this is typically done using a <b><c:if></b> block, but that&#8217;s a very verbose solution.
</p>
<p>
<b>JSP 2.0</b> adds a new conditional operator to the <b>Expression Language(EL)</b> to deal with this case in a more elegant way.The<br />
<b>conditional operator</b> exists in many programming languages (for instance, in Java, C, and JavaScript), so you<br />
may have seen it before. It takes a Boolean condition and one result to use if the condition is true and another<br />
if it&#8217;s false. I use a very simple example to demonstrate the usage :</p>
<p><p>
1) File Name : <b>firstPage.jsp</b></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="language" style="font-family:monospace;">&lt;html&gt;
	&lt;head&gt;
	&lt;script language=&quot;javascript&quot;&gt;
		function checkNumber()
		{
			var number = document.forms['myForm'].numberTxt.value;
			if(number &lt; 1 || number &gt; 5 || isNaN(number))
			{
				alert(&quot;Please enter a number between 1 and 5&quot;);
				return false;
			}
		}
	&lt;/script&gt;
	&lt;/head&gt;
	&lt;body&gt;
		&lt;form name=&quot;myForm&quot; method=&quot;post&quot; action=&quot;secondPage.jsp&quot;&gt;
			Please enter a number between 1 and 5 and press the Ok button :
			&lt;br /&gt;
			&lt;input type=&quot;text&quot; id=&quot;numberTxt&quot; name=&quot;numberTxt&quot; /&gt;
			&lt;br /&gt;
			&lt;input type=&quot;submit&quot; name=&quot;btnSubmit&quot; value=&quot;Ok&quot; onclick=&quot;return(checkNumber());&quot;/&gt;
		&lt;/form&gt;
	&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>2) File Name : <b>secondPage.jsp</b></p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>

<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
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;form&gt;
		&lt;select&gt;
			&lt;option value=&quot;1&quot; ${param.numberTxt == 1 ? 'selected' : ''}&gt;Suresh&lt;/option&gt;
			&lt;option value=&quot;2&quot; ${param.numberTxt == 2 ? 'selected' : ''}&gt;Ramesh&lt;/option&gt;
			&lt;option value=&quot;3&quot; ${param.numberTxt == 3 ? 'selected' : ''}&gt;Naresh&lt;/option&gt;
			&lt;option value=&quot;4&quot; ${param.numberTxt == 4 ? 'selected' : ''}&gt;Rajeev&lt;/option&gt;
			&lt;option value=&quot;5&quot; ${param.numberTxt == 5 ? 'selected' : ''}&gt;Pawan&lt;/option&gt;
		&lt;/select&gt;
	&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

</p>
<h2>Explantion:</h2>
<p>
	In the first page I enter a number between 1 and 5 and click the submit button. The request is submitted to the second page. In the second page I have used a drop down list to display some names. Out of these names one of them gets selected depending on what value is entered in the first page.
</p>
<p>
	I use the <b>param</b> expressions language implicit object,which contains a map of request parameters, to<br />
	fetch the value of <b>numberTxt</b> parameter. The value is compared with fixed constants for each <b>option</b> tag. If an expression returns true, the string <b>selected</b> is replaced in its place. In case the expression<br />
	retuns false <b>blank string</b> is replaced.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2009/02/ternary-operator-in-jsp-2-0-expression-languageel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
