<?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>J2EE &#8211; Jitendra Zaa</title>
	<atom:link href="https://www.jitendrazaa.com/blog/tag/j2ee/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.jitendrazaa.com/blog</link>
	<description>AI, Salesforce, ServiceNow &#38; Enterprise Tech Guides</description>
	<lastBuildDate>Fri, 15 Apr 2011 09:43:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.1</generator>
<site xmlns="com-wordpress:feed-additions:1">87744916</site><atom:link rel="search" type="application/opensearchdescription+xml" title="Search Jitendra Zaa" href="https://www.jitendrazaa.com/blog/wp-json/opensearch/1.1/document" />	<item>
		<title>Tutorial of Simple JSP Tiles application without Struts</title>
		<link>https://www.jitendrazaa.com/blog/java/jsp/tutorial-of-simple-jsp-tiles-application-without-struts/</link>
					<comments>https://www.jitendrazaa.com/blog/java/jsp/tutorial-of-simple-jsp-tiles-application-without-struts/#comments</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Fri, 15 Apr 2011 09:43:15 +0000</pubDate>
				<category><![CDATA[JSP]]></category>
		<category><![CDATA[J2EE]]></category>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=2034</guid>

					<description><![CDATA[Example of Simple JSP Tiles application without Struts]]></description>
										<content:encoded><![CDATA[<p>There are very few resources available on internet which explains step by step integration of tiles in simple jsp page.<br />
<a title="Apache Tiles" href="http://tiles.apache.org/">Apache Tilesâ„¢</a> is a templating framework built to simplify the development of web application user interfaces.</p>
<p>Tiles allows authors to define page fragments which can be assembled into a complete page at runtime. These fragments, or tiles, can be used as simple includes in order to reduce the duplication of common page elements or embedded within other tiles to develop a series of reusable templates. These templates streamline the development of a consistent look and feel across an entire application.</p>
<p><strong>Ste p1 : </strong>Download the Tiles jar file from <a title="Download Tiles jar file" href="http://tiles.apache.org/download.html" target="_blank">here</a>.<span id="more-2034"></span></p>
<p><strong>Step 2 : </strong>Add following jar files in the lib folder of the web application.</p>
<blockquote><p>commons-beanutils-1.8.0.jar<br />
commons-digester-2.0.jar<br />
jcl-over-slf4j-1.5.8.jar<br />
log4j-over-slf4j-1.6.1.jar<br />
servlet-api.jar<br />
slf4j-api-1.5.8.jar<br />
slf4j-jdk14-1.5.8.jar<br />
tiles-api-2.2.2.jar<br />
tiles-core-2.2.2.jar<br />
tiles-jsp-2.2.2.jar<br />
tiles-servlet-2.2.2.jar<br />
tiles-servlet-wildcard-2.2.2.jar<br />
tiles-template-2.2.2.jar</p></blockquote>
<p><strong>Step 3: </strong>Create following jsp pages:<br />
banner.jsp, common_menu.jsp, credits.jsp, cssPath.jsp, home_body.jsp and SideBar.jsp.</p>
<p><strong>Step 4: </strong>Create a master layout page.</p>
<pre class="brush: xml; highlight: [11,15,22,28,38]; title: ; notranslate">
&lt;%@ taglib uri=&quot;http://tiles.apache.org/tags-tiles&quot; prefix=&quot;tiles&quot;%&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;tiles:getAsString name=&quot;title&quot; /&gt;
&lt;/title&gt;
&lt;tiles:insertAttribute name=&quot;cssFile&quot;&gt;&lt;/tiles:insertAttribute&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;div id=&quot;wrapper&quot;&gt;
		&lt;div id=&quot;menu&quot;&gt;
			&lt;tiles:insertAttribute name=&quot;menu&quot; /&gt;
		&lt;/div&gt;

		&lt;div id=&quot;header&quot;&gt;
			&lt;tiles:insertAttribute name=&quot;header&quot; /&gt;
		&lt;/div&gt;

		&lt;div id=&quot;page&quot;&gt;
			&lt;div id=&quot;page-bgtop&quot;&gt;
				&lt;div id=&quot;page-bgbtm&quot;&gt;
					&lt;div id=&quot;content&quot;&gt;
						&lt;tiles:insertAttribute name=&quot;body&quot; /&gt;

						&lt;div style=&quot;clear: both;&quot;&gt;&amp;nbsp;&lt;/div&gt;
					&lt;/div&gt;

					&lt;div id=&quot;sidebar&quot;&gt;
						&lt;tiles:insertAttribute name=&quot;sideBar&quot; /&gt;
					&lt;/div&gt;

					&lt;div style=&quot;clear: both;&quot;&gt;&amp;nbsp;&lt;/div&gt;
				&lt;/div&gt;
			&lt;/div&gt;
		&lt;/div&gt;

	&lt;/div&gt;
	&lt;div id=&quot;footer&quot;&gt;
		&lt;tiles:insertAttribute name=&quot;footer&quot; /&gt;
	&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>As you can see, <strong>tiles:insertAttribute</strong> tag is used. It will work as placeholder and will be replaced by actual pages at run time as per definition in &#8220;<em><span style="text-decoration: underline;">tiles-defs.xml</span></em>&#8221;</p>
<p><a title="Tiles Tag" href="http://tiles.apache.org/migration/tags.html">Read more on configuring tiles attributes.</a></p>
<p>Below output shows the layout.</p>
<p style="text-align: center;">&nbsp;</p>
<figure id="attachment_2037" aria-describedby="caption-attachment-2037" style="width: 463px" class="wp-caption aligncenter"><a href="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2011/04/Simple-JSP-Tiles-without-Struts.jpg?ssl=1"><img data-recalc-dims="1" fetchpriority="high" decoding="async" class="size-full wp-image-2037  " title="Simple JSP Tiles without Struts" src="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2011/04/Simple-JSP-Tiles-without-Struts.jpg?resize=463%2C331&#038;ssl=1" alt="Simple JSP Tiles without Struts" width="463" height="331" /></a><figcaption id="caption-attachment-2037" class="wp-caption-text">Simple JSP Tiles without Struts</figcaption></figure>
<p><strong>Step 5: </strong>Now create a &#8220;<em><span style="text-decoration: underline;">tiles-defs.xml</span></em>&#8221; in WEB-INF Folder, which have all the configuration.</p>
<pre class="brush: xml; highlight: [6]; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot; ?&gt;
&lt;!DOCTYPE tiles-definitions PUBLIC
       &quot;-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN&quot;
       &quot;http://tiles.apache.org/dtds/tiles-config_2_1.dtd&quot;&gt;
&lt;tiles-definitions&gt;
  &lt;definition name=&quot;myapp.homepage&quot; template=&quot;/layouts/classic.jsp&quot;&gt;
    &lt;put-attribute name=&quot;title&quot; value=&quot;Simple Tiles application without Struts&quot; /&gt;
    &lt;put-attribute name=&quot;header&quot; value=&quot;/tiles/banner.jsp&quot; /&gt;
    &lt;put-attribute name=&quot;menu&quot; value=&quot;/tiles/common_menu.jsp&quot; /&gt;
    &lt;put-attribute name=&quot;body&quot; value=&quot;/tiles/home_body.jsp&quot; /&gt;
    &lt;put-attribute name=&quot;footer&quot; value=&quot;/tiles/credits.jsp&quot; /&gt;
    &lt;put-attribute name=&quot;cssFile&quot; value=&quot;/tiles/cssPath.jsp&quot; /&gt;
    &lt;put-attribute name=&quot;sideBar&quot; value=&quot;/tiles/SideBar.jsp&quot; /&gt;
  &lt;/definition&gt;
&lt;/tiles-definitions&gt;
</pre>
<p>The attribute &#8220;name&#8221; defined in tag &#8220;<em><span style="text-decoration: underline;">tiles:insertAttribute</span></em>&#8221; comes from above configuration file and replaced by the pages specified.</p>
<p><strong>Step 6 :</strong> Now create the jsp page which uses the Tiles template defined above.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=ISO-8859-1&quot;
    pageEncoding=&quot;ISO-8859-1&quot;%&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
&lt;%@ taglib uri=&quot;http://tiles.apache.org/tags-tiles&quot; prefix=&quot;tiles&quot; %&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot;&gt;
&lt;title&gt;Insert title here&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;tiles:insertDefinition name=&quot;myapp.homepage&quot; /&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Template name &#8220;myapp.homepage&#8221; is looked up into file &#8220;<em><span style="text-decoration: underline;">tiles-defs.xml</span></em>&#8221; and configuration is applied at runtime as per definition.</p>
<blockquote><p><a href="https://jitendrazaa.com/blog/wp-content/uploads/2011/04/TilesDemo.zip">Download the war file from here</a>, change extension from &#8220;zip&#8221; to &#8220;war&#8221;.</p></blockquote>
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/java/jsp/tutorial-of-simple-jsp-tiles-application-without-struts/feed/</wfw:commentRss>
			<slash:comments>18</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2034</post-id>	</item>
		<item>
		<title>Java &#8211; J2EE Interview Questions &#8211; 1</title>
		<link>https://www.jitendrazaa.com/blog/java/java-j2ee-interview-questions-1/</link>
					<comments>https://www.jitendrazaa.com/blog/java/java-j2ee-interview-questions-1/#comments</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Fri, 15 Apr 2011 05:58:18 +0000</pubDate>
				<category><![CDATA[JAVA]]></category>
		<category><![CDATA[J2EE]]></category>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=2017</guid>

					<description><![CDATA[JAVA - J2EE Interview Questions - 1, JAVA - J2EE Interview Questions - 1,custom tag  JSP, Externalization , serialVersionUID, difference between interface and abstract class, iterate  HashMap ]]></description>
										<content:encoded><![CDATA[<p><strong>1. What is Generic Servlet ?</strong><br />
<strong> Answer :</strong> Defines a generic, protocol-independent servlet. <a title="GenericServlet API" href="http://download.oracle.com/javaee/5/api/javax/servlet/GenericServlet.html" target="_blank">GenericServlet </a>implements the <a title="Servlet API" href="http://download.oracle.com/javaee/5/api/javax/servlet/Servlet.html" target="_blank"><em>Servlet </em></a>and <a title="ServletConfig API" href="http://download.oracle.com/javaee/5/api/javax/servlet/ServletConfig.html" target="_blank"><em>ServletConfig</em></a> interfaces. <em>GenericServlet </em>makes writing servlets easier. It provides simple versions of the lifecycle methods <em>init </em>and <em>destroy</em>. To use Protocol specific servlet like http protocol, we can use <a title="HttpServlet" href="http://download.oracle.com/javaee/5/api/javax/servlet/http/HttpServlet.html" target="_blank">HttpServlet</a>. Difference in HttpServlet and GenericServlet is that, HttpServlet provides few more methods like <em>doGet </em>and <em>doPost</em>. Same operations can be done in <em>service</em> method of generic servlet.  Read <a title="Servlet Life Cycle" href="https://jitendrazaa.com/blog/java/servlet/life-cycle-of-servlet/" target="_blank">Servlet Life cycle</a></p>
<hr />
<p><strong>2. Can abstract class have Constructor ?</strong><br />
<strong> Answer : </strong>Yes. abstract class can have a constructor.</p>
<hr />
<p><strong>3. We cannot instantiate the abstract class, then what is the need of constructor and how it is called.</strong><br />
<strong> Answer : </strong>You may have not come across this situation. but answer i very easy. If want to initialize few parameters for all the subclasses then we can use the constructor of abstract class. Constructor calling mechanism is same as normal inheritance in java. Default constructor gets called automatically and to call other constructors we have to explicitly call it by using keyword &#8220;super&#8221;.</p>
<hr />
<p><strong><span id="more-2017"></span>4. Does java have virtual function ?</strong><br />
<strong> Answer : </strong>As such there is no keyword &#8220;<em>virtual</em>&#8221; present in java. but except static, final and private method all the methods are virtual bu default.  Refer <a title="Virtual function in java" href="https://jitendrazaa.com/blog/java/virtual-function-in-java/" target="_blank">this </a>article to read more on it.</p>
<hr />
<p><strong>5. How you will create custom tag in JSP ?</strong><br />
<strong> Answer : </strong></p>
<ol>
<li>Create tld file in &#8220;WEB-INF/tlds&#8221; folder and configure required properties.</li>
<li>Create a class which implements interface <a title="Tag interface API" href="http://download.oracle.com/javaee/1.4/api/javax/servlet/jsp/tagext/Tag.html" target="_blank">Tag </a>/ <a title="BodyTag Interface" href="http://download.oracle.com/javaee/1.4/api/javax/servlet/jsp/tagext/BodyTag.html" target="_blank">BodyTag </a>or extends class <a title="TagSupport API" href="http://download.oracle.com/javaee/1.4/api/javax/servlet/jsp/tagext/TagSupport.html" target="_blank">TagSupport </a>/ <a title="BodyTagSupport API" href="http://download.oracle.com/javaee/1.4/api/javax/servlet/jsp/tagext/BodyTagSupport.html" target="_blank">BodyTagSupport</a>. In that class write getter and setter for defined property. Few methods required by interface are <em>doStartTag()</em>, <em>doEndTag() </em>and <em>release()</em>. Read how to <a title="Create Custom Tag" href="https://jitendrazaa.com/blog/java/how-to-create-jsp-custom-tag-%E2%80%93-using-bodytag-interface-or-bodytagsupport/" target="_blank">create custom tag</a> in detail.</li>
</ol>
<hr />
<p><strong>6. What is Externalization ?</strong><br />
<strong> Answer :</strong> Externalization is the interface provided by the JAVA which extends interface Serializable. It provides two more methods as compared to Serializable interface &#8211;</p>
<ol>
<li>void readExternal(ObjectInput in)</li>
<li>void writeExternal(ObjectOutput out)</li>
</ol>
<p>The above two methods gives the flexibility and control over how the object is serialized and deserialized. for further read <a title="Externalization Tutorial" href="https://jitendrazaa.com/blog/java/explain-externalizable-in-java/">refer this article</a>.</p>
<hr />
<p><strong>7. What is the use of serialVersionUID in JAVA ?</strong><br />
<strong> Answer : </strong>Whenever object is created, one unique ID is associated with object and its implementation may defer from compiler to compiler. Whenever any object is serialized and deserealized, this variable is used to determine whether the object is in same state or not ? assignment of default serialVersionUID is mostly depends upon the methods and fields present in class and if any field is added or removed from the class definition then its serialVersionUID also changes and if the value does not match then it results in &#8220;InvalidClassException&#8221;. Because of this reason it is recommended to have a default unique serialVersionUID with each serialized undergoing class. To read in detail with example, <a title="Tutorial of serialVersionUID in JAVA" href="https://jitendrazaa.com/blog/java/explain-serialversionuid-in-java/" target="_blank">refer this article</a>.</p>
<hr />
<p><strong>8. If i don&#8217;t want to serialize some fields in class, then how to achieve this ?</strong><br />
<strong> Answer :</strong> This question can also be asked as &#8220;What is the <strong>transient</strong> variable ?&#8221;. &#8220;<strong>transient variables and static variables</strong>&#8221; can be used to avoid the field being serialized in Java. (As static variable is class level variable, and it does not associated at object level &#8211; it is not serialized).</p>
<hr />
<p><strong>9. What will happen if one of the members in the class doesn&#8217;t implement Serializable interface?</strong><br />
<strong> Answer :</strong> If you try to serialize an object of a class which implements Serializable, but the object includes a reference to an non- Serializable class then a &#8220;˜<strong><a title="Java API" href="http://download.oracle.com/javase/6/docs/api/java/io/NotSerializableException.html" target="_blank">NotSerializableException</a></strong>&#8216; will be thrown at runtime.</p>
<hr />
<p><strong>10. If a class is Serializable but its super class in not, what will be the state of the instance variables inherited from super class after deserialization?</strong><br />
<strong> Answer : </strong>Java serialization process only continues in object hierarchy till the class is Serializable and values of the instance variables inherited from super class will be initialized <strong>by calling constructor</strong> of Non-Serializable Super class during deserialization process .</p>
<hr />
<p><strong>11. What is the conceptual difference between interface and abstract class ? When to use interface and abstract class ?</strong><br />
<strong> Answer :</strong></p>
<p><strong>Abstract class and its usage </strong>:</p>
<p>A class which is partially implemented and have few abstract methods are know an &#8220;<strong>abstract class</strong>&#8220;. few developers think that why anybody should create a partial implementation ? The best example i have in my mind is &#8220;DataMapper Pattern&#8221;. For the CRUD operation &#8211; open connection and close connection and sequence of save method will be known to the programmer however which query will be executed to save or retrieve differs for different object. in that case createInsertSQL() method can be made abstract and internally save() will call openConnection() and closeConnection() which is implemented. below code snap explains the save() method.</p>
<pre class="brush: java; title: ; notranslate">
abstract public String createInsertSQL();//abstract method

public void save() //method implemented
{
     try{
          openConnection();//method implemented
          String sql = createInsertSQL(); //abstract method
          executeStatement();//method implemented
      }
      catch(SQLException ex){

     }
     finally{
        closeconnection();//method implemented
     }
}

</pre>
<p>As you can see in above code snap, only unknown implementation is the SQL Query which is made abstract and others are implemented. and therefore underlying child class must implement the method createInsertSQL() and call save().<br />
<strong> </strong></p>
<p><strong>Interface and its usage :</strong><br />
interface are also known as &#8220;contract&#8221;. when we know the skeleton/ structure of the class but it complete implementation differs then we must use interface. in following scenario we must use interface :</p>
<ol>
<li>Dependency injection</li>
<li>Runtime polymorphism</li>
</ol>
<p>In design pattern programming to interface is preferable rather than programming to implementation (inheritance).</p>
<hr />
<p><strong>12. How to iterate over keys of HashMap in JDK 4 and 5?</strong><br />
<strong>Answer :</strong> This is the common question asked in interview.</p>
<p><strong>In JAVA 5 : </strong>we can use advance for loop as shown in above code, use map.keySet(). This will return the <a title="Set Interface API" href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/Set.html" target="_blank">Set </a>(As Keys must be unique)</p>
<p><strong>In JAVA 4 :</strong> use map.keySet() and get the <a title="Iterator API" href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/Iterator.html" target="_blank">Iterator </a>object using map.<a title="iterator() method API" href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/Set.html#iterator%28%29" target="_blank">iterate()</a> . then using while loop , get the value for each key.</p>
<hr />
<p><strong>13. What is Exception chaining  and how to achieve ?</strong><br />
<strong> Answer :</strong> When one exception causes another exception then the second exception must print the log of the first exception also.</p>
<p>We can use initcause() method of the &#8220;Throwable&#8221; class to retain the cause of exception.</p>
<p><a title="Exception chaining" href="https://jitendrazaa.com/blog/java/exception-chaining/">Read more..</a></p>
<hr />
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/java/java-j2ee-interview-questions-1/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2017</post-id>	</item>
		<item>
		<title>J2EE &#8211; Servlet , JSP , JSF and JMS Version Table</title>
		<link>https://www.jitendrazaa.com/blog/java/jsp/j2ee-servlet-jsp-jsf-and-jms-version-table/</link>
					<comments>https://www.jitendrazaa.com/blog/java/jsp/j2ee-servlet-jsp-jsf-and-jms-version-table/#comments</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Wed, 13 Apr 2011 10:24:00 +0000</pubDate>
				<category><![CDATA[JSP]]></category>
		<category><![CDATA[Servlet]]></category>
		<category><![CDATA[J2EE]]></category>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=1976</guid>

					<description><![CDATA[J2EE - Servlet , JSP , JSF and JMS Version Table]]></description>
										<content:encoded><![CDATA[<p>Hi Friends,</p>
<p>Below table gives the information about the versions of J2EE (Java Table Version).</p>

<table id="tablepress-1" class="tablepress tablepress-id-1">
<thead>
<tr class="row-1">
	<th class="column-1"><div> </div></th><th class="column-2"><div>J2EE 1.2</div></th><th class="column-3"><div><a href="http://java.sun.com/j2ee/1.3/docs/">J2EE 1.3</a></div></th><th class="column-4"><div><a href="http://java.sun.com/j2ee/1.4/docs/">J2EE 1.4</a></div></th><th class="column-5"><div>JEE 5</div></th><th class="column-6"><div> <a href="http://www.oracle.com/technetwork/java/javaee/tech/index.html">JEE 6</a><br/><a href="http://www.javabeat.net/articles/99-new-features-in-java-ee-60-1.html">new</a></div></th>
</tr>
</thead>
<tbody class="row-striping row-hover">
<tr class="row-2">
	<td class="column-1"><a href="http://en.wikipedia.org/wiki/Java_Servlet">Servlet</a></td><td class="column-2">2.2</td><td class="column-3">2.3</td><td class="column-4">2.4</td><td class="column-5">2.5 <a href="http://www.javabeat.net/articles/100-new-features-in-servlets-25-1.html">new</a></td><td class="column-6">3 <a href="http://www.javabeat.net/articles/97-new-features-in-servlets-30-1.html"> new </a></td>
</tr>
<tr class="row-3">
	<td class="column-1"><a href="http://en.wikipedia.org/wiki/JavaServer_Pages">JSP</a></td><td class="column-2">1.1</td><td class="column-3">1.2</td><td class="column-4">2.0 <a href="http://www.javabeat.net/tips/145-new-features-in-jsp-20.html">new</a></td><td class="column-5">2.1</td><td class="column-6">2.2</td>
</tr>
<tr class="row-4">
	<td class="column-1"><a href="http://en.wikipedia.org/wiki/JavaServer_Pages_Standard_Tag_Library">JSTL</a></td><td class="column-2">-</td><td class="column-3">-</td><td class="column-4">1.1</td><td class="column-5">1.2</td><td class="column-6">1.2</td>
</tr>
<tr class="row-5">
	<td class="column-1">Tomcat</td><td class="column-2">4.x</td><td class="column-3">5.x</td><td class="column-4">5.x</td><td class="column-5">6.x</td><td class="column-6">7.x</td>
</tr>
<tr class="row-6">
	<td class="column-1"><a href="http://en.wikipedia.org/wiki/Java_Message_Service">JMS</a></td><td class="column-2">1.0.2</td><td class="column-3">1.0.2</td><td class="column-4">1.1</td><td class="column-5">1.1</td><td class="column-6">1.1</td>
</tr>
<tr class="row-7">
	<td class="column-1"><a href="http://en.wikipedia.org/wiki/JavaServer_Faces">JSF</a></td><td class="column-2">-</td><td class="column-3">-</td><td class="column-4">-</td><td class="column-5">1.2</td><td class="column-6">2.0 <a href="http://www.javabeat.net/tips/116-new-features-in-jsf-20.html">new</a></td>
</tr>
<tr class="row-8">
	<td class="column-1">J2EE Release Date</td><td class="column-2">Dec 12, 1999</td><td class="column-3">Sep 24, 2001</td><td class="column-4">Nov 11, 2003</td><td class="column-5">May 11 , 2006</td><td class="column-6">Dec 2009</td>
</tr>
<tr class="row-9">
	<td class="column-1"><a href="http://en.wikipedia.org/wiki/Enterprise_JavaBean">EJB</a></td><td class="column-2">1.1</td><td class="column-3">2.0</td><td class="column-4">2.1</td><td class="column-5">3.0</td><td class="column-6">3.0</td>
</tr>
<tr class="row-10">
	<td class="column-1">Extra Info</td><td class="column-2">-</td><td class="column-3">-</td><td class="column-4">-</td><td class="column-5">-</td><td class="column-6">JDK 5 and above required</td>
</tr>
</tbody>
</table>
<!-- #tablepress-1 from cache -->
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/java/jsp/j2ee-servlet-jsp-jsf-and-jms-version-table/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1976</post-id>	</item>
		<item>
		<title>Create Servlet using Annotation &#8211; Servlet 3.0</title>
		<link>https://www.jitendrazaa.com/blog/java/servlet/create-servlet-using-annotation/</link>
					<comments>https://www.jitendrazaa.com/blog/java/servlet/create-servlet-using-annotation/#respond</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Wed, 13 Apr 2011 09:53:55 +0000</pubDate>
				<category><![CDATA[Servlet]]></category>
		<category><![CDATA[J2EE]]></category>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=1959</guid>

					<description><![CDATA[Create the Servlet without any deployment descriptor. Using Annotations]]></description>
										<content:encoded><![CDATA[<p><a title="Version table of J2EE" href="https://jitendrazaa.com/blog/java/servlet/j2ee-servlet-jsp-jsf-and-jms-version-table/" target="_blank">Before reading this article, i will suggest readers to go through the version table of J2EE.</a></p>
<p>One of the most appraised feature of Servlet 3.0 is the support of the annotations to create the Servlet. Before  this the Deployment Descriptor (web.xml) was used to create the servlet mapping , defining init parameters etc. All the settings can be now achieved without any entry in web.xml.</p>
<p><span style="text-decoration: underline;"><strong>Prerequisite:</strong></span></p>
<ol>
<li>JDK 5.0 and above.</li>
<li>Tomcat 7</li>
<li>Eclipse 3.6 &#8211; Helios (as of now, it only supports Tomcat 7)</li>
</ol>
<p>We will start with creating the Servlet class :<span id="more-1959"></span></p>
<pre class="brush: java; highlight: [13,14,15,16,17,18,19,20,21]; title: ; notranslate">
package com.g2.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(
		name=&quot;TestServlet&quot;,
		urlPatterns={&quot;/test&quot;,&quot;/testServlet&quot;},
		initParams={
				@WebInitParam(name=&quot;db&quot;,value=&quot;Oracle&quot;),
				@WebInitParam(name=&quot;jdk&quot;,value=&quot;6&quot;),
				@WebInitParam(name=&quot;tomcat&quot;,value=&quot;7&quot;)
				}
			)
public class ServletUsingAnnotation extends HttpServlet{

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
		PrintWriter pw = res.getWriter();

		res.setContentType(&quot;text/html&quot;);
		pw.write(&quot;Running Servlet using Annotation..&quot;);
		pw.write(&quot;&lt;br /&gt;&quot;);
		pw.write(&quot;-- Init parameters --&quot;);
		pw.write(&quot;&lt;br /&gt;&quot;);
		pw.write(&quot;db : &quot;+this.getInitParameter(&quot;db&quot;));
		pw.write(&quot;&lt;br /&gt;&quot;);
		pw.write(&quot;jdk : &quot;+this.getInitParameter(&quot;jdk&quot;));
		pw.write(&quot;&lt;br /&gt;&quot;);
		pw.write(&quot;tomcat : &quot;+this.getInitParameter(&quot;tomcat&quot;));
	}
}
</pre>
<p>As you can see in above code, we have used annotation &#8220;<strong>@WebServlet</strong>&#8221; to declare this class as servlet. to pass the init parameter to servlet, we have used &#8220;<strong>@WebInitParam</strong>&#8220;. Before Servlet 2.5 we were not able to specify multiple url for the same servlet. As you can see in above code, we have given two URLs for the same servlet.</p>
<p>Create &#8220;index.jsp&#8221; page :</p>
<pre class="brush: xml; title: ; notranslate">
&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=ISO-8859-1&quot;
    pageEncoding=&quot;ISO-8859-1&quot;%&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot;&gt;
&lt;title&gt;Creating servlet using Annotation&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;a href=&quot;../test&quot;&gt;Servlet using Annotation&lt;/a&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>After clicking on hyperlink on page &#8220;index.jsp&#8221; Servlet will open with following output.</p>
<blockquote><p>Running Servlet using Annotation..<br />
&#8212; Init parameters &#8212;<br />
db : Oracle<br />
jdk : 6<br />
tomcat : 7</p></blockquote>
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/java/servlet/create-servlet-using-annotation/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1959</post-id>	</item>
		<item>
		<title>Cause and solution of &#8220;org.hibernate.LazyInitializationException: could not initialize proxy &#8211; no Session&#8221; error</title>
		<link>https://www.jitendrazaa.com/blog/java/hibernate/cause-and-solution-of-org-hibernate-lazyinitializationexception-could-not-initialize-proxy-no-session-error/</link>
					<comments>https://www.jitendrazaa.com/blog/java/hibernate/cause-and-solution-of-org-hibernate-lazyinitializationexception-could-not-initialize-proxy-no-session-error/#comments</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Tue, 22 Feb 2011 17:42:12 +0000</pubDate>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[J2EE]]></category>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=1543</guid>

					<description><![CDATA[Cause and solution of "org.hibernate.LazyInitializationException: could not initialize proxy - no Session" error]]></description>
										<content:encoded><![CDATA[<p>In Hibernate, a common error faced by lots of developer is <strong>&#8220;org.hibernate.LazyInitializationException: could not initialize proxy &#8211; no Session</strong>&#8220;. In lots of forum the answer is no answer and most of forum have answer but there is no explanation for the beginners.</p>
<p>First, Lets reproduce this error in Hibernate.</p>
<p>Assume that Hibernate configuration (<strong>hibernate.cfg.xml</strong>) and  mapping file is already written.<span id="more-1543"></span></p>
<p>Consider below snap of code and assume that function is written in class &#8220;DBManager&#8221;.</p>
<pre class="brush: java; title: ; notranslate">
 public List&lt;ChatMessage&gt; getMessages() {
            List&lt;ChatMessage&gt; MessageList = new ArrayList&lt;ChatMessage&gt;();
            Configuration cf = new Configuration().configure();
            SessionFactory factory = cf.buildSessionFactory();
            Session session = null;
            try {
                  session = factory.openSession();
                  String SQL_QUERY = &quot;from ChatMessage c&quot;;
                  Query query = session.createQuery(SQL_QUERY);
                  Iterator&lt;ChatMessage&gt; it = query.iterate();
                  while (it.hasNext()) {
                        ChatMessage c = it.next();
                        MessageList.add(c);
                         //If below line is commented then code throws an error
                        //System.out.println(&quot;In Manager - Msg - &quot;+c.getMessage());
                  }

            } catch (Exception e) {
                  e.printStackTrace();
            } finally {
                  session.close();
            }

            return MessageList;
      }
</pre>
<p>In above code, i am trying to fetch the collection of class &#8220;ChatMessage&#8221;. In while loop, simply i am adding the object in ArrayList and at the end i am returning the List. <strong>Check that i have commented the SOP statement</strong> at the end of while loop.</p>
<p>Lets consider that other class is invoking this code. Code snap of other class is:</p>
<pre class="brush: java; title: ; notranslate">
List&lt;ChatMessage&gt; msgList = dbManager.getMessages();
                  System.out.println(&quot; Size : &quot;+msgList.size());
                  for(ChatMessage chatMsg : msgList)
                  {
                        out.println(olMsg+&quot;&lt;span style='background:#&quot;+colorCode+&quot;'&gt;&quot;+chatMsg.getUserName()+&quot;&lt;/span&gt;&quot;+chatMsg.getMessage()+&quot;&lt;br/&gt;&lt;br/&gt;&quot;);
                  }
</pre>
<p>Whenever this code executes, <strong>it will throw an error</strong> inside for loop at &#8220;chatMsg.getUserName()&#8221; because the lazy loading is true by default and as error also describes this. <strong>The best solution is to make &#8220;lazyLoad=false&#8221; in configuration file</strong>. The code will then run perfect, but why this error did come?</p>
<p>This error means that you&#8217;re trying to access a <strong>lazily-loaded property or collection</strong>, but the hibernate session is closed or not available .<strong> Lazy loading in Hibernate means that the object will not be populated (via a database query) until the property/collection is accessed in code.</strong> Hibernate accomplishes this by creating a dynamic proxy object that will hit the database only when you first use the object. In order for this to work, your object must be attached to an open Hibernate session throughout it&#8217;s lifecycle.</p>
<p>When we uncomment the SOP statement, program runs successfully, because it hits the object and therefore it initializes itself through hibernate session.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/java/hibernate/cause-and-solution-of-org-hibernate-lazyinitializationexception-could-not-initialize-proxy-no-session-error/feed/</wfw:commentRss>
			<slash:comments>10</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1543</post-id>	</item>
		<item>
		<title>Difference in SendRedirect() and RequestDispatcher() in Servlet</title>
		<link>https://www.jitendrazaa.com/blog/java/servlet/difference-in-sendredirect-and-requestdispatcher-in-servlet/</link>
					<comments>https://www.jitendrazaa.com/blog/java/servlet/difference-in-sendredirect-and-requestdispatcher-in-servlet/#comments</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Sat, 12 Feb 2011 19:17:14 +0000</pubDate>
				<category><![CDATA[Servlet]]></category>
		<category><![CDATA[J2EE]]></category>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=1501</guid>

					<description><![CDATA[difference in SendRedirect() and RequestDispatcher() in Servlet]]></description>
										<content:encoded><![CDATA[<p><strong>SendRedirect</strong></p>
<ul>
<li>This is the method of object <strong>HttpServlerResponse</strong>.</li>
<li>Request is redirected to client (Browser), and it will process the new URL.</li>
<li>End User can see on which page, url is redirected.</li>
<li>In Nutshell, <strong>Processing done at client side</strong>.</li>
</ul>
<p><strong>RequestDispatcher</strong></p>
<ul>
<li>This object can be accessed from <strong>HttpServletRequest</strong>.</li>
<li>Servlet will internally forward the request to another servlet or jsp page.</li>
<li>End user don&#8217;t know that which page is processed internally.</li>
<li>In Nutshell,<strong> Processing done at server side.</strong></li>
</ul>
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/java/servlet/difference-in-sendredirect-and-requestdispatcher-in-servlet/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1501</post-id>	</item>
		<item>
		<title>Life Cycle of Servlet</title>
		<link>https://www.jitendrazaa.com/blog/java/servlet/life-cycle-of-servlet/</link>
					<comments>https://www.jitendrazaa.com/blog/java/servlet/life-cycle-of-servlet/#comments</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Sat, 12 Feb 2011 18:29:39 +0000</pubDate>
				<category><![CDATA[Servlet]]></category>
		<category><![CDATA[J2EE]]></category>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=1494</guid>

					<description><![CDATA[Explain Life Cycle of Servlet]]></description>
										<content:encoded><![CDATA[<p>Servlet is used in J2EE to create the dynamic web pages under Java Environment.  Like Applets, Servlet also have init() and destroy() methods. In this article i will explain the Life cycle of servlet.</p>
<p><strong>Step 1 </strong>: After Compilation of the Servlet, the class file is loaded by the loader.</p>
<p><strong>Step 2 </strong>: Then the Container instantiates the Servlet class by calling default Constructor. <a href="https://jitendrazaa.com/blog/java/servlet/how-container-handles-the-servlet-request/" target="_blank">Read this article to know more that how container works for Servlet</a>.</p>
<figure id="attachment_1496" aria-describedby="caption-attachment-1496" style="width: 452px" class="wp-caption aligncenter"><a href="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2011/02/Servlet-Life-Cycle.jpg?ssl=1"><img data-recalc-dims="1" decoding="async" class="size-full wp-image-1496  " title="Servlet Life Cycle" src="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2011/02/Servlet-Life-Cycle.jpg?resize=452%2C305&#038;ssl=1" alt="Servlet Life Cycle" width="452" height="305" /></a><figcaption id="caption-attachment-1496" class="wp-caption-text">Servlet Life Cycle</figcaption></figure>
<p><strong><span id="more-1494"></span>Step 3</strong>: At Step 2, the Servlet object is just normal java object. <strong>It is the init() method which is just called after the instantiation of object and gives the Servletness to object. Like applets, this method is called only once in life cycle. </strong><a href="https://jitendrazaa.com/blog/java/example-to-override-the-init-method-of-the-servlet/" target="_blank">It is recommended not to override the init() method but if you want to override then read this article.</a></p>
<p><strong>Step 4 : </strong>Then <strong>Service()</strong> method is called and this is the place <strong>where servlet spends most of its life. </strong>Each request here comes as a separate thread.  This method then internally calls the doGet() or doPost() method depending upon the type of request comes.</p>
<p><strong>Step 5 :</strong> <strong>destroy()</strong> method is called just before destroying the Servlet. This method should be used if any clean code needs to be run before destroying the servlet.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/java/servlet/life-cycle-of-servlet/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1494</post-id>	</item>
		<item>
		<title>How container handles the Servlet request</title>
		<link>https://www.jitendrazaa.com/blog/java/servlet/how-container-handles-the-servlet-request/</link>
					<comments>https://www.jitendrazaa.com/blog/java/servlet/how-container-handles-the-servlet-request/#comments</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Sat, 12 Feb 2011 12:32:45 +0000</pubDate>
				<category><![CDATA[Servlet]]></category>
		<category><![CDATA[J2EE]]></category>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=1482</guid>

					<description><![CDATA[How container handles the Servlet request or How the apache Tomcat works]]></description>
										<content:encoded><![CDATA[<p>1. User clicks a link that has a URL of Servlet.</p>
<figure id="attachment_1485" aria-describedby="caption-attachment-1485" style="width: 495px" class="wp-caption aligncenter"><a href="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2011/02/Client-Browse-Servlet-URL.jpg?ssl=1"><img data-recalc-dims="1" decoding="async" class="size-full wp-image-1485 " title="Client Browse Servlet URL" src="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2011/02/Client-Browse-Servlet-URL.jpg?resize=495%2C189&#038;ssl=1" alt="Client Browse Servlet URL" width="495" height="189" /></a><figcaption id="caption-attachment-1485" class="wp-caption-text">Client Browse Servlet URL</figcaption></figure>
<p><span id="more-1482"></span>2. Container (Apache Tomcat is one of the example) sees that the request is for servlet , so create two objects :<br />
<strong>HttpServletRequest<br />
HttpServletResponse</strong></p>
<figure id="attachment_1486" aria-describedby="caption-attachment-1486" style="width: 463px" class="wp-caption aligncenter"><a href="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2011/02/HttpServletRequest-and-HttpServletResponse.jpg?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" class="size-full wp-image-1486" title="HttpServletRequest and HttpServletResponse" src="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2011/02/HttpServletRequest-and-HttpServletResponse.jpg?resize=463%2C179&#038;ssl=1" alt="HttpServletRequest and HttpServletResponse" width="463" height="179" /></a><figcaption id="caption-attachment-1486" class="wp-caption-text">HttpServletRequest and HttpServletResponse</figcaption></figure>
<p>3. Container finds correct servlet on the basis of URL passed with the help <strong>deployment descriptor</strong> (web.xml) file. Creates / Allocate thread for that request and pass request and response object to servle thread.</p>
<figure id="attachment_1487" aria-describedby="caption-attachment-1487" style="width: 437px" class="wp-caption aligncenter"><a href="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2011/02/Create-Thread-for-Servlet.jpg?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" class="size-full wp-image-1487" title="Create Thread for Servlet" src="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2011/02/Create-Thread-for-Servlet.jpg?resize=437%2C180&#038;ssl=1" alt="Create Thread for Servlet" width="437" height="180" /></a><figcaption id="caption-attachment-1487" class="wp-caption-text">Create Thread for Servlet</figcaption></figure>
<p>4. Container calls the servlets <strong>service()</strong> method, on the type of request, service calls <strong>doGet() or doPost()</strong> methods.</p>
<figure id="attachment_1488" aria-describedby="caption-attachment-1488" style="width: 462px" class="wp-caption aligncenter"><a href="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2011/02/Service-method-of-servlet.jpg?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" class="size-full wp-image-1488" title="Service method of servlet" src="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2011/02/Service-method-of-servlet.jpg?resize=462%2C277&#038;ssl=1" alt="Service method of servlet" width="462" height="277" /></a><figcaption id="caption-attachment-1488" class="wp-caption-text">Service method of servlet</figcaption></figure>
<p>5. Lets assume that service calls the doPost() method. doPost() method<strong> generates dynamic page</strong> and add the page in response object.</p>
<figure id="attachment_1489" aria-describedby="caption-attachment-1489" style="width: 469px" class="wp-caption aligncenter"><a href="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2011/02/Servlet-doPost-response-object.jpg?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" class="size-full wp-image-1489" title="Servlet - doPost  - response object" src="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2011/02/Servlet-doPost-response-object.jpg?resize=469%2C223&#038;ssl=1" alt="Servlet - doPost  - response object" width="469" height="223" /></a><figcaption id="caption-attachment-1489" class="wp-caption-text">Servlet - doPost - response object</figcaption></figure>
<p>6. Thread completes, container <strong>converts the response object into HttpResponse</strong> object and <strong>destroys the response and request object</strong>.</p>
<figure id="attachment_1490" aria-describedby="caption-attachment-1490" style="width: 475px" class="wp-caption aligncenter"><a href="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2011/02/destroy-response-and-request-object.jpg?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" class="size-full wp-image-1490 " title="destroy response and request object" src="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2011/02/destroy-response-and-request-object.jpg?resize=475%2C169&#038;ssl=1" alt="destroy response and request object" width="475" height="169" /></a><figcaption id="caption-attachment-1490" class="wp-caption-text">destroy response and request object</figcaption></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/java/servlet/how-container-handles-the-servlet-request/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1482</post-id>	</item>
		<item>
		<title>Example to Override the init() method of the servlet</title>
		<link>https://www.jitendrazaa.com/blog/java/servlet/example-to-override-the-init-method-of-the-servlet/</link>
					<comments>https://www.jitendrazaa.com/blog/java/servlet/example-to-override-the-init-method-of-the-servlet/#comments</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Thu, 10 Feb 2011 20:28:00 +0000</pubDate>
				<category><![CDATA[Servlet]]></category>
		<category><![CDATA[J2EE]]></category>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=1479</guid>

					<description><![CDATA[Example to Override the init() method of the servlet]]></description>
										<content:encoded><![CDATA[<p>It is not recommended to override the init() method of the servlet.</p>
<p>Here is an example to override init() method of servlet:</p>
<pre class="brush: java; title: ; notranslate">
    public class BookDBServlet ... {

        private BookstoreDB books;

        public void init(ServletConfig config) throws ServletException {

            // Store the ServletConfig object and log the initialization
            super.init(config);

            // Load the database to prepare for requests
            books = new BookstoreDB();
        }
        ...
    }
</pre>
<p>you must write  <strong>super.init(config) </strong>code and after that program specific logic.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/java/servlet/example-to-override-the-init-method-of-the-servlet/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1479</post-id>	</item>
		<item>
		<title>Why not to write constructor in Servlet</title>
		<link>https://www.jitendrazaa.com/blog/java/servlet/why-not-to-write-constructor-in-servlet/</link>
					<comments>https://www.jitendrazaa.com/blog/java/servlet/why-not-to-write-constructor-in-servlet/#respond</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Thu, 10 Feb 2011 20:24:14 +0000</pubDate>
				<category><![CDATA[Servlet]]></category>
		<category><![CDATA[J2EE]]></category>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=1477</guid>

					<description><![CDATA[Why not to write constructor in Servlet]]></description>
										<content:encoded><![CDATA[<p>Technically you can define constructors in servlet. But, the declared constructor cannot access the <strong>ServletConfig </strong>object or throw a <strong>ServletException</strong>.</p>
<p>Then why is it not customary to declare a constructor in a servlet? Because the <strong>init()</strong> method is used to perform servlet initialization. In JDK 1.0 (servlet were written in this version), constructors for dynamically loaded Java classes such as servlets cannot accept arguments. Therefore<strong> init() was used to initialize by passing the implemented object of ServletConfig interface and other needed parameters.</strong><br />
Also, Java constructors cannot be declared in interfaces. So,<strong> javax.servlet.Servlet</strong> interface cannot have a constructor that accepts a ServletConfig parameter. To overcome this, init() method is used for initialization instead of declaring a constructor.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/java/servlet/why-not-to-write-constructor-in-servlet/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1477</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Minified using Disk

Served from: www.jitendrazaa.com @ 2026-07-17 17:57:28 by W3 Total Cache
-->