<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-5956132650471213105</atom:id><lastBuildDate>Wed, 15 May 2013 11:52:18 +0000</lastBuildDate><category>JSF 2.0</category><category>apache</category><category>tomcat clustering</category><category>JasperReports</category><category>attack</category><category>charts</category><category>grub</category><category>SSH</category><category>iReport</category><category>bootloader</category><category>javaSE7</category><category>security</category><category>vulnerability</category><category>virtual hosting</category><category>Kernel</category><category>Java</category><category>themes</category><category>session replication</category><category>load balancer</category><category>SSH Tunneling</category><category>Tomcat</category><category>nginx</category><category>Linux</category><category>javaEE</category><category>Java SE</category><category>multiple_instances</category><category>sqlinjection</category><category>Java EE 6</category><category>JSF</category><category>CDI</category><category>mod_jk</category><category>javaSE</category><category>screencast</category><title>Ramki Java Blog</title><description>Discuss Java Concepts</description><link>http://www.ramkitech.com/</link><managingEditor>noreply@blogger.com (Rama krishnnan E P)</managingEditor><generator>Blogger</generator><openSearch:totalResults>30</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/ramki/feeds" /><feedburner:info uri="ramki/feeds" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>ramki/feeds</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-2570542160608564795</guid><pubDate>Mon, 28 Jan 2013 15:06:00 +0000</pubDate><atom:updated>2013-04-12T11:16:22.882+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">multiple_instances</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">mod_jk</category><category domain="http://www.blogger.com/atom/ns#">tomcat clustering</category><category domain="http://www.blogger.com/atom/ns#">nginx</category><category domain="http://www.blogger.com/atom/ns#">load balancer</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">session replication</category><title>Tomcat Clustering Series Part 5 : NginX as Load Balancer</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
Hi this is&amp;nbsp;my fifth part of the&amp;nbsp;&lt;a href="http://www.ramkitech.com/search/label/tomcat%20clustering" target="_blank"&gt;Tomcat Clustering Series&lt;/a&gt;.&amp;nbsp;In this&amp;nbsp;post we are going to discuss how to replace Apache httpd load balancer to Nginx as a load balancer.&amp;nbsp;&lt;b style="background-color: #fff2cc; color: #660000;"&gt;[Check the video below for better understanding]&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Hi i finished &lt;a href="http://www.ramkitech.com/search/label/tomcat%20clustering" target="_blank"&gt;Tomcat Clustering Series&lt;/a&gt;. In these series we have 2 big setups needed for Tomcat Clustering&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Setup and configure the Load Balancer&lt;/li&gt;
&lt;li&gt;Configure the Session Replication in Tomcat.&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-9nG82vXSuFw/UHUS9R5_9pI/AAAAAAAACmw/QMlhCCwySiw/s1600/tomcat_simple_load_balancer.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="205" src="http://2.bp.blogspot.com/-9nG82vXSuFw/UHUS9R5_9pI/AAAAAAAACmw/QMlhCCwySiw/s400/tomcat_simple_load_balancer.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
In first setup, we configure the Load Balancer using Apache httpd web server. Its open source and widely used.&lt;br /&gt;
&lt;div&gt;
Second setup is session replication in Tomcat through modify/add &amp;lt;cluster&amp;gt; tag in server.xml file. These tomcat instance may&lt;a href="http://www.ramkitech.com/2011/07/running-multiple-tomcat-instances-on.html" target="_blank"&gt; run on&amp;nbsp;single&amp;nbsp;machine&lt;/a&gt; or different machine.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
In our &lt;a href="http://www.ramkitech.com/search/label/tomcat%20clustering" target="_blank"&gt;Tomcat Clustering Series&lt;/a&gt;, the big part is configure the Load balancer (Apache httpd web server). Because&amp;nbsp;there&amp;nbsp;are lots of steps are involved&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;Install the Apache httpd web server from either source or repo&lt;/li&gt;
&lt;li&gt;Compile and install the mod_jk connector&lt;/li&gt;
&lt;li&gt;Create the workers.properties file (add tomcat IP and ajp port information )&lt;/li&gt;
&lt;li&gt;Configure into httpd.conf file (Add mod_jk related settings)&lt;/li&gt;
&lt;/ol&gt;
these&amp;nbsp;setups&amp;nbsp;are take &lt;b&gt;&lt;u&gt;more time and very difficult to debug.&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="color: #660000; font-size: large;"&gt;&lt;b&gt;Is there is any alternative to load balancer?&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&amp;nbsp; &amp;nbsp; Yes, Nginx its emerging web server. this post we are going to discuss how to setup nginx as a load&amp;nbsp;balancer&amp;nbsp;in our tomcat cluster.&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="color: #660000; font-size: large;"&gt;&lt;b&gt;What is Nginx?&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;a href="http://en.wikipedia.org/wiki/Nginx" target="_blank"&gt;Nginx&lt;/a&gt; is open source and alternative to Apache httpd web server. Its provide more performance and little memory foot print.&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="color: #660000; font-size: large;"&gt;&lt;b&gt;Install Nginx&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&amp;nbsp; &amp;nbsp; we can install nginx through either repository (apt-get,yum) or from source. here i m build nginx from source from &lt;a href="http://nginx.org/en/download.html" target="_blank"&gt;here&lt;/a&gt;. then extract the compressed file.&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;div&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;./configure --help &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
above command shows possible command line options available for compile&lt;/div&gt;
&lt;div&gt;
for install use this command&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;./configure &amp;nbsp; --prefix=/home/ramki/nginx &amp;nbsp; --with-http_ssl_module &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
here&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: blue;"&gt;--prefix&lt;/span&gt; used to specify where nginx server want to install, here i m using my home folder (like /usr/local/nginx)&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: blue;"&gt;--with-http_ssl_module&lt;/span&gt; here i&amp;nbsp;specified&amp;nbsp;install SSL module (https), its not necessary. If we want secure webpage then this module is needed.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
then compile the source&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: #fff2cc;"&gt;&amp;nbsp;&lt;b&gt;make&lt;/b&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
install the nginx based on our configuration&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;sudo make install &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
now installation is done, To &lt;u&gt;start the nginx&lt;/u&gt;,&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;cd&amp;nbsp;/home/ramki/nginx/sbin &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;sudo ./nginx &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
now open browser and go to http://localhost to get nginx default page.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
To &lt;u&gt;stop the nginx&lt;/u&gt;, we need to pass stop signal via -s option&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;sudo ./nginx &amp;nbsp;-s stop &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #660000; font-size: large;"&gt;&lt;b&gt;Configure as a Load Balancer&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;Nginx&amp;nbsp;configurations&amp;nbsp;are stored in nginx.con file in conf/ folder. &amp;nbsp;We need to perform 2 steps to make nginx as load balancer.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 style="text-align: left;"&gt;
&lt;span style="color: purple;"&gt;First define Upstream&amp;nbsp;block&amp;nbsp;in nginx.conf file&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Upstream&amp;nbsp;block&amp;nbsp;provides simple load-balancing across upstream (backend) servers. In upstream block have unique name (here &amp;nbsp;tomcatcluster), later we need to point out from other block.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div style="color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;"&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;upstream tomcatcluster &amp;nbsp;{&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;"&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;b style="font-size: 12.727272033691406px;"&gt;&lt;span style="white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;span style="background-color: #fff2cc;"&gt;server&amp;nbsp;&lt;a href="http://127.0.0.1:8181/" style="color: #1155cc;" target="_blank"&gt;127.0.0.1:8181&lt;/a&gt;;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style="color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;"&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;&lt;span style="white-space: pre-wrap;"&gt;                &lt;/span&gt;server&amp;nbsp;&lt;a href="http://127.0.0.1:8282/" style="color: #1155cc;" target="_blank"&gt;127.0.0.1:8282&lt;/a&gt;;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;"&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;&lt;span style="white-space: pre-wrap;"&gt;                &lt;/span&gt;server&amp;nbsp;&lt;a href="http://127.0.0.1:8383/" style="color: #1155cc;" target="_blank"&gt;127.0.0.1:8383&lt;/a&gt;;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;"&gt;
&lt;b style="background-color: #fff2cc; font-size: 12.727272033691406px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/b&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
here we define the&amp;nbsp;back-end&amp;nbsp;servers (Tomcat instances) via server directive.&lt;/div&gt;
&lt;div&gt;
In each server directive we mention IP address of server and&amp;nbsp;HTTP&amp;nbsp;port number(&lt;b&gt;Not AJP port number&lt;/b&gt;).&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 style="text-align: left;"&gt;
&lt;span style="color: purple;"&gt;Second forward (proxy) the request to&amp;nbsp;back-end&amp;nbsp;servers&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;This step is forward the request to upstream blocks, where we&amp;nbsp;define&amp;nbsp;the back end servers.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div style="color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;"&gt;
&lt;span style="background-color: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;location / {&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;"&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;proxy_pass&amp;nbsp;&lt;a href="http://tomcatcluster/" style="color: #1155cc;" target="_blank"&gt;http://tomcatcluster&lt;/a&gt;;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;"&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
here if location / is already present, then remove and add this new one.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
here proxy_pass directive,&amp;nbsp;proxifier(forward)&amp;nbsp;the requests to upstream servers. here tomcatcluster is name of the upstream block and we used http protocol to forward the request.&lt;/div&gt;
&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
that's&amp;nbsp;it. Load balancer is ready.&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
now start the tomcat instances based on my previous post (session replication). then start nginx.&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
now access http://localhost.&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
now nginx forward the request in round robin fashion to&amp;nbsp;back-end&amp;nbsp;servers. all servers have the session, so it can able to process the request&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
This is same as non-sticky&amp;nbsp;session method we used in my previous posts.&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
If we want sticky session, then nginx&amp;nbsp;directly&amp;nbsp;not provide, but some 3rd party patches are&amp;nbsp;available. but nginx provide ip_hash directive. Its forward all request from&amp;nbsp;single&amp;nbsp;IP to same tomcat like sticky session. But sticky session works based on cookie (session). but ip_hash is based on IP address of client.&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
If u want to configure ip_hash, then modify the upstream block, add ip_hash&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;div style="color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;"&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;upstream tomcatcluster &amp;nbsp;{&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;"&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ip_hash;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;"&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;b style="font-size: 12.727272033691406px;"&gt;&lt;span style="white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;span style="background-color: #fff2cc;"&gt;server&amp;nbsp;&lt;a href="http://127.0.0.1:8181/" style="color: #1155cc;" target="_blank"&gt;127.0.0.1:8181&lt;/a&gt;;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style="color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;"&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;&lt;span style="white-space: pre-wrap;"&gt;                &lt;/span&gt;server&amp;nbsp;&lt;a href="http://127.0.0.1:8282/" style="color: #1155cc;" target="_blank"&gt;127.0.0.1:8282&lt;/a&gt;;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;"&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;&lt;span style="white-space: pre-wrap;"&gt;                &lt;/span&gt;server&amp;nbsp;&lt;a href="http://127.0.0.1:8383/" style="color: #1155cc;" target="_blank"&gt;127.0.0.1:8383&lt;/a&gt;;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;"&gt;
&lt;b style="background-color: #fff2cc; font-size: 12.727272033691406px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/b&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
just restart the server, u feel like sticky session concept.&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
when we compare the Nginx to Apache httpd web server, nginx is provide simple&amp;nbsp;configuration, and can handle huge amount of traffic, consume little memory foot print and its take little CPU load.&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
search &lt;span style="background-color: #d9ead3;"&gt;Nginx vs Apache&lt;/span&gt; we get some&amp;nbsp;amazing&amp;nbsp;benchmark results.&amp;nbsp;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="color: #660000; font-size: large;"&gt;&lt;b&gt;Screen Cast :&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;iframe allowfullscreen="" frameborder="0" height="480" src="http://www.youtube.com/embed/zRPJ_U2MruU" width="700"&gt;&lt;/iframe&gt;

&lt;br /&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=61_jrlzUdzs:vhulzUt8v-M:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=61_jrlzUdzs:vhulzUt8v-M:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=61_jrlzUdzs:vhulzUt8v-M:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?i=61_jrlzUdzs:vhulzUt8v-M:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=61_jrlzUdzs:vhulzUt8v-M:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ramki/feeds/~4/61_jrlzUdzs" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ramki/feeds/~3/61_jrlzUdzs/tomcat-clustering-series-part-5-nginx.html</link><author>noreply@blogger.com (Rama krishnnan E P)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-9nG82vXSuFw/UHUS9R5_9pI/AAAAAAAACmw/QMlhCCwySiw/s72-c/tomcat_simple_load_balancer.png" height="72" width="72" /><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /><feedburner:origLink>http://www.ramkitech.com/2013/01/tomcat-clustering-series-part-5-nginx.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-4326698037755275470</guid><pubDate>Wed, 05 Dec 2012 13:54:00 +0000</pubDate><atom:updated>2013-04-12T11:17:20.967+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">multiple_instances</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">mod_jk</category><category domain="http://www.blogger.com/atom/ns#">tomcat clustering</category><category domain="http://www.blogger.com/atom/ns#">load balancer</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">session replication</category><title>Tomcat Clustering Series Part 4 : Session Replication using Backup Manager</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
Hi this is&amp;nbsp;my fourth part of the&amp;nbsp;&lt;a href="http://www.ramkitech.com/search/label/tomcat%20clustering" target="_blank"&gt;Tomcat Clustering Series&lt;/a&gt;.&amp;nbsp;In this&amp;nbsp;post we are going to discuss the how to setup session replication using Backup Manager in tomcat clustering environment. Session replication makes High availability and full fail-over capability to our clustering environment.&lt;b style="background-color: #fff2cc; color: #660000;"&gt;[Check the video below for better understanding]&lt;/b&gt;&lt;br /&gt;
&lt;b style="background-color: #fff2cc; color: #660000;"&gt;&lt;br /&gt;&lt;/b&gt;
Its continuation of the &lt;a href="http://www.ramkitech.com/2012/11/tomcat-clustering-series-part-3-session.html" target="_blank"&gt;last post (session replication using Delta Manager)&lt;/a&gt;. In delta manager each tomcat instance need to replicate the session information to all other tomcat instances. Its take more time and replication if our cluster size is increased. so there is alternative manager is there. Its Backup Manager.&lt;br /&gt;
&lt;br /&gt;
Backup Manager is&amp;nbsp;replicate&amp;nbsp;the copy of session data to &lt;b&gt;&lt;u&gt;exactly one&lt;/u&gt;&lt;/b&gt; other tomcat instances. This big difference between both managers. here which tomcat creates that is &lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;primary copy&lt;/b&gt;&lt;/span&gt; of the session. and another tomcat whose hold the replicate session is &lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;backup copy&lt;/b&gt;&lt;/span&gt;. If any one of the tomcat is down. back up tomcat serve the session. Its&amp;nbsp;achieve&amp;nbsp;the&amp;nbsp;fail over&amp;nbsp;capability.&lt;br /&gt;
&lt;br /&gt;
The setup process of backup manager is same as Delta manager. except we need to mention the Manager as BacupManager (&lt;span style="background-color: white; color: #dd1144; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; line-height: 16px; white-space: pre;"&gt;org.apache.catalina.ha.session.DeltaManager&lt;/span&gt;) &amp;nbsp;inside &amp;lt;Cluster&amp;gt; element.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Suppose we have 3 tomcat instances like &lt;a href="http://www.ramkitech.com/2012/11/tomcat-clustering-series-part-3-session.html" target="_blank"&gt;previous post&lt;/a&gt;. and i&amp;nbsp;configured&amp;nbsp;into backup manager.&lt;br /&gt;
&lt;br /&gt;
now user try access the page. User request comes to load balancer, and load balancer redirect the rquest to suppose tomcat1. Now tomcat one create the session, now tomcat1 is&amp;nbsp;responsible&amp;nbsp;to&amp;nbsp;replicate&amp;nbsp;exactly one copy to any one of the tomcat. so&amp;nbsp;tomcat1&amp;nbsp;picks any tomcat which is part of the cluster (multicast). here tomcat1 picks tomcat3 as a backup. so tomcat3 hold the backup copy of the session.&lt;br /&gt;
&lt;br /&gt;
we are run the load balancer in sticky session mode. so all further request from that particular user &amp;nbsp;is&amp;nbsp;redirect&amp;nbsp;to tomcat1 only. all modification in tomcat1 is replicate to tomcat3.&lt;br /&gt;
&lt;br /&gt;
now tomcat1 is&amp;nbsp;crashed/shutdown for some reason&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-D3AA9gQBYpk/UL9Ls6hChHI/AAAAAAAACr0/LgO94l_udaY/s1600/session-replicate_backup_manager.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="226" src="http://1.bp.blogspot.com/-D3AA9gQBYpk/UL9Ls6hChHI/AAAAAAAACr0/LgO94l_udaY/s400/session-replicate_backup_manager.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
now same user try to&amp;nbsp;access&amp;nbsp;the page. this time load balancer try to redirect to tomcat1. but tomcat1 is down. so&amp;nbsp;load-balancer&amp;nbsp;pick one tomcat from the remaining tomcats. here&amp;nbsp;interestingly&amp;nbsp;2 case are there.&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style="text-align: left;"&gt;
&lt;span style="color: #660000;"&gt;Case 1:&lt;/span&gt;&lt;/h3&gt;
&amp;nbsp; Suppose Load balancer pick the tomcat3 then tomcat3 receive the request and tomcat3 itself hold the backup copy of the session. so tomcat3 make that session as primary copy and tomcat3 pick any one tomcat as backup copy. so here remaining only one tomcat is there. so tomcat3 replicate the session to tomcat2. so now tomcat3 hold primary copy and tomcat2 hold the backup copy. now tomcat3 give the response to user. all further request is handled by tomcat3 (sticky session).&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style="text-align: left;"&gt;
&lt;span style="color: #990000;"&gt;case 2:&lt;/span&gt;&lt;/h3&gt;
&amp;nbsp;Suppose Load balancer pick the tomcat2 then tomcat2 receive the request and tomcat2 don't have the session. so tomcat2 session manager (Backup Manager) ask to all other tomcat manager "hi anybody hold the session for this user (based on session id [cookie])". Actually tomcat3 have the backup session. so tomcat3 inform to tomcat2. and replicate the&amp;nbsp;session&amp;nbsp;to tomcat2. now &amp;nbsp;tomcat2 make that session as primary copy and tomcat3 whose already have copy of session as&amp;nbsp;remains&amp;nbsp;as a backup copy of that session. so now tomcat2 hold primary copy and tomcat3 hold the backup copy. now tomcat2 give the response to user. all further request is handled by tomcat2 (sticky session).&lt;br /&gt;
&lt;br /&gt;
so in either case our session is replicate and maintained by backup manager. Its good for large cluster.&lt;br /&gt;
check the&amp;nbsp;video&amp;nbsp;below&lt;br /&gt;
&lt;br /&gt;
check my configuration in &lt;a href="https://github.com/ramkicse/tomcat-clustering-session-replication-" target="_blank"&gt;my github repo&lt;/a&gt; or get as &lt;a href="https://github.com/ramkicse/tomcat-clustering-session-replication-/archive/master.zip" target="_blank"&gt;ZIP&lt;/a&gt;&amp;nbsp;file&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;h3 style="text-align: left;"&gt;
&lt;a name="loadbalancerfail"&gt;
&lt;span style="color: #660000;"&gt;Note:&lt;/span&gt;&lt;/h3&gt;
&lt;/a&gt;
&lt;br /&gt;
Load balancer also faces &lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;single point failure&lt;/b&gt;&lt;/span&gt;. to resolve this we need to put another load balancer with public address and update the new IP to DNS server with same URL. so our URL like example.com query resolves the 2 IP address for 2 load balancer.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #990000;"&gt;How its work:-&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
-&amp;gt; If browser want to access http://example.com then it first ask DNS server.&lt;br /&gt;
-&amp;gt; DNS server gives 2 IP address to browser&lt;br /&gt;
-&amp;gt; Browser take the first IP address and try to connect.&lt;br /&gt;
-&amp;gt; If in the case that server is failed to respond then browser side make timeout&lt;br /&gt;
-&amp;gt; then browser contact second IP address, now second load balancer is works fine.&lt;br /&gt;
&lt;br /&gt;
This kind of adding more load balancer makes to our website more&amp;nbsp;scalable&amp;nbsp;and reliable in case of tragedy.&lt;br /&gt;
&lt;br /&gt;
check in ur terminal&lt;br /&gt;
&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;&amp;gt; &amp;nbsp; &amp;nbsp; nslookup google.com &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
its gives 11 IP address. these all are google&amp;nbsp;load balancer's located in various&amp;nbsp;geographic&amp;nbsp;locations&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
Another thing this DNS servers not return same order of IP list to browser. each an every time its rotate(round robin) the IP list. so in 2 different machine ask google.com get different order of IP list. so these 2 differnt machine connect different google load balancer. so here DNS server also play little role for distribute the requests(loads).&lt;br /&gt;
&lt;br /&gt;
to verify use same command twice. and verify the IP order.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;span style="color: #660000;"&gt;Screen Cast:&lt;/span&gt;&lt;/h2&gt;
&lt;br /&gt;
&lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="480" src="http://www.youtube.com/embed/vgbUKiNg6lU" width="700"&gt;&lt;/iframe&gt;

&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=nXnPKBxmnLg:LS43nQfAgTA:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=nXnPKBxmnLg:LS43nQfAgTA:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=nXnPKBxmnLg:LS43nQfAgTA:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?i=nXnPKBxmnLg:LS43nQfAgTA:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=nXnPKBxmnLg:LS43nQfAgTA:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ramki/feeds/~4/nXnPKBxmnLg" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ramki/feeds/~3/nXnPKBxmnLg/tomcat-clustering-series-part-4-session.html</link><author>noreply@blogger.com (Rama krishnnan E P)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-D3AA9gQBYpk/UL9Ls6hChHI/AAAAAAAACr0/LgO94l_udaY/s72-c/session-replicate_backup_manager.png" height="72" width="72" /><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /><feedburner:origLink>http://www.ramkitech.com/2012/12/tomcat-clustering-series-part-4-session.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-5838067658082292351</guid><pubDate>Tue, 20 Nov 2012 06:28:00 +0000</pubDate><atom:updated>2013-04-12T11:17:28.154+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">multiple_instances</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">mod_jk</category><category domain="http://www.blogger.com/atom/ns#">tomcat clustering</category><category domain="http://www.blogger.com/atom/ns#">load balancer</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">session replication</category><title>Tomcat Clustering Series Part 3 : Session Replication</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
Hi this is&amp;nbsp;my third part of the&amp;nbsp;&lt;a href="http://www.ramkitech.com/search/label/tomcat%20clustering" target="_blank"&gt;Tomcat Clustering Series&lt;/a&gt;.&amp;nbsp;In this&amp;nbsp;post we are going to discuss the how to setup session replication in tomcat clustering environment. Session replication makes High availability and full fail-over capability to our clustering environment.&lt;b style="background-color: #fff2cc; color: #660000;"&gt;[Check the video below for better understanding]&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In my previous post we&amp;nbsp;discussed about setup &lt;a href="http://www.ramkitech.com/2012/10/tomcat-clustering-series-simple-load.html" target="_blank"&gt;simple load balancer&lt;/a&gt; and how to make &lt;a href="http://www.ramkitech.com/2012/10/tomcat-clustering-series-part-2-session.html" target="_blank"&gt;session affinity&lt;/a&gt; concepts.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #660000; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"&gt;&lt;b&gt;How to setup Session Replication in tomcat&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;before going to session replication we need to understand 2 important concepts&lt;br /&gt;
&lt;div style="text-align: left;"&gt;
&lt;/div&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;Multicast&lt;/li&gt;
&lt;li&gt;Session Manager in Tomcat&lt;/li&gt;
&lt;/ul&gt;
&lt;span style="color: #990000; font-size: large;"&gt;&lt;b&gt;Multicast&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #990000; font-size: large;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;div style="text-align: left;"&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Multicast" target="_blank"&gt;Multicast&lt;/a&gt; is To transmit a single message to a select group of recipients. here&amp;nbsp;multicast&amp;nbsp;used by tomcat cluster to identify the instances those part of cluster.&amp;nbsp;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
There is&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt; 2 types of cluster&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;/div&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;Static Tomcat Cluster&lt;/li&gt;
&lt;li&gt;Dynamic&amp;nbsp;Tomcat Cluster&lt;/li&gt;
&lt;/ul&gt;
In&lt;span style="background-color: #d9ead3;"&gt; &lt;b&gt;static cluster&lt;/b&gt;&lt;/span&gt; there is no need multicast, because each tomcat we statically defined/configured the other instances. But &lt;span style="background-color: #d9ead3;"&gt;&lt;b&gt;dynamic Cluster&lt;/b&gt;&lt;/span&gt; we are not&amp;nbsp;defined&amp;nbsp;anything. so each tomcat in that cluster some how to identify the other tomcat instances.&lt;br /&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
so here&amp;nbsp;multicast&amp;nbsp;concepts is used. each and every tomcat first&amp;nbsp;joining&amp;nbsp;to &lt;b style="background-color: #fff2cc;"&gt;single&amp;nbsp;multicast&amp;nbsp;group&lt;/b&gt;. and send the heartbeat signals in periodic interval. so other tomcat instances&amp;nbsp;received&amp;nbsp;these signal and add the member to the cluster.&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="color: #990000; font-size: large;"&gt;&lt;b&gt;Session Manager in Tomcat&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #990000; font-size: large;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; Session Manager is used to create and manage the session behalf the application. In Servlet Specification&lt;b style="background-color: #fff2cc;"&gt;&lt;span style="color: #e06666;"&gt; &lt;/span&gt;&lt;span style="color: blue;"&gt;request.getSession();&lt;/span&gt;&lt;/b&gt; line is mention that container (tomcat) is responsible for create the session. here tomcat use the Session Manager for this purpose.&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
there is &lt;b style="background-color: #fff2cc;"&gt;4 types of Session Manager&lt;/b&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;/div&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;Standard Manager&lt;/li&gt;
&lt;li&gt;Persistent Manager&lt;/li&gt;
&lt;li&gt;Delta Manager&lt;/li&gt;
&lt;li&gt;Backup Manager&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 style="text-align: left;"&gt;
&lt;span style="color: #cc0000;"&gt;Standard Manager&lt;/span&gt;&lt;/h3&gt;
&lt;div style="text-align: left;"&gt;
Its is the default manager used by tomcat. Even though we are not mention in our web application tomcat use this manager for managing our session. If u want to customize the this&amp;nbsp;standard&amp;nbsp;manager then add &amp;lt;Manager&amp;gt; tag in context.xml file.&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;
&lt;div style="text-align: center;"&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;&amp;lt;Manager className=“org.apache.catalina.session.StandardManager” /&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
here&amp;nbsp;&lt;span style="background-color: #fce5cd;"&gt;org.apache.catalina.session.StandardManager &lt;/span&gt;is fully qualified class name of the Standard Manager.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 style="text-align: left;"&gt;
&lt;span style="color: #cc0000;"&gt;Persistent Manger&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
This mnager is to sote the session information into persistent place after some interval. here two types of store is available.&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;File Store&lt;/li&gt;
&lt;li&gt;JDBC Store&lt;/li&gt;
&lt;/ul&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;File Store&lt;/b&gt;&lt;/span&gt; helps to store all session information in&amp;nbsp;separate&amp;nbsp;files in&amp;nbsp;underlying&amp;nbsp;file system (local HDD or shared&amp;nbsp;file-system&amp;nbsp;like NFS,..)&amp;nbsp;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;b style="background-color: #fff2cc;"&gt;JDBC Store&lt;/b&gt; helps to store the session information to&amp;nbsp;relational&amp;nbsp;database.&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
so using the Persistent&amp;nbsp;Manager we can&amp;nbsp;achieve&amp;nbsp;the tomcat cluster. but its not&amp;nbsp;swapped&amp;nbsp;out in real time. its pushes the information after certain interval. so if anything badly happen(crash) before that interval then in-memory session data is gone.&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;h3 style="text-align: left;"&gt;
&lt;span style="color: #cc0000;"&gt;Delta Manger&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
In this post we are going to use this manager. Its replicate the session to all other instances. so this manager&amp;nbsp;usually&amp;nbsp;used&amp;nbsp;clustered&amp;nbsp;environment. but not good for large cluster.&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;h3 style="text-align: left;"&gt;
&lt;span style="color: #cc0000;"&gt;Backup Manager&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
this manager&amp;nbsp;usually&amp;nbsp;used&amp;nbsp;clustered&amp;nbsp;environment. Its like delta manger. but it will &amp;nbsp;replicate to exactly one other instance(backup instance). Its acted like one instance is Primary &amp;nbsp;and another instance as backup &amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;b style="color: #660000; font-size: x-large;"&gt;Steps to make Session Replication in Tomcat Clustering&lt;/b&gt;&lt;br /&gt;
&lt;b style="color: #660000; font-size: x-large;"&gt;&lt;br /&gt;&lt;/b&gt;
here i will continue from exactly where i left in last &lt;a href="http://www.ramkitech.com/2012/10/tomcat-clustering-series-part-2-session.html" target="_blank"&gt;session affinity post&lt;/a&gt;. so check that &lt;a href="http://www.ramkitech.com/2012/10/tomcat-clustering-series-part-2-session.html" target="_blank"&gt;post&lt;/a&gt; and make sure jumRoute all are set properly. so&amp;nbsp;steps&amp;nbsp;are&lt;br /&gt;
&lt;div style="text-align: left;"&gt;
&lt;/div&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;Enable Multicast routing&lt;/li&gt;
&lt;li&gt;Add &amp;lt;Cluster&amp;gt; Entries in conf/server.xml file&amp;nbsp;for all instances.&lt;/li&gt;
&lt;li&gt;Enable the Web Application as distributable&lt;/li&gt;
&lt;/ol&gt;
&lt;ul style="text-align: left;"&gt;
&lt;/ul&gt;
&lt;h3 style="text-align: left;"&gt;
&lt;span style="color: #cc0000;"&gt;1. Enable Multicast routing&lt;/span&gt;&lt;/h3&gt;
&lt;div&gt;
&lt;span style="color: #cc0000;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;In Linux Environment most of the system kernel is capable to process the multicast address. but we need to add route entry in kernel routing table.&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;/div&gt;
&lt;div style="text-align: center;"&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;sudo route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
here eth0 is my&amp;nbsp;Ethernet&amp;nbsp;interface. so change&amp;nbsp;according&amp;nbsp;to your &amp;nbsp;interface&lt;br /&gt;
&lt;div&gt;
In&amp;nbsp;multicast&amp;nbsp;address is belong to Class D address Range&lt;span style="background-color: #d9ead3;"&gt; (224.0.0.0 to 239.255.255.255).&lt;/span&gt; so we inform to kernel if any one&amp;nbsp;access&amp;nbsp;these address then it goes through eth0 interface.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 style="text-align: left;"&gt;
&lt;span style="color: #cc0000;"&gt;2. Add &amp;lt;Cluster&amp;gt; Entries in conf/server.xml file&amp;nbsp;for all instances.&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #cc0000;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;This very important part for tomcat clustering. We need to Add &amp;lt;Cluster&amp;gt; tag in &lt;span style="background-color: #d9ead3;"&gt;&lt;b&gt;conf/server.xml &lt;/b&gt;&lt;/span&gt;file in all tomcat instances.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div style="text-align: center;"&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;&amp;lt;Cluster className=&lt;span style="color: magenta;"&gt;"org.apache.catalina.ha.tcp.SimpleTcpCluster"&lt;/span&gt;/&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
we can add this &amp;lt;Cluster&amp;gt; tag in either inside the&amp;lt;Engine&amp;gt; tag or &amp;lt;Host&amp;gt; tag.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
here SimpleTcpCluster is Tomcat&amp;nbsp;Cluster&amp;nbsp;implementation&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
This tag is looks like simple but its has many inner tags. if we&amp;nbsp;omitted&amp;nbsp;then its takes the default&amp;nbsp;values. if we want do any cutomization (like change multicat address, receving address port) we need to use complete &amp;lt;Cluster&amp;gt; tag&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
this is complete &amp;lt;Cluster&amp;gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&amp;lt;Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; channelSendOptions="8"&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;         &lt;/span&gt;&amp;lt;Manager className="org.apache.catalina.ha.session.DeltaManager"&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;                            &lt;/span&gt;expireSessionsOnShutdown="false"&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;                            &lt;/span&gt;notifyListenersOnReplication="true"/&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span class="Apple-tab-span" style="background-color: #fff2cc; white-space: pre;"&gt;&lt;span style="color: #20124d;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;         &lt;/span&gt;&amp;lt;Channel className="org.apache.catalina.tribes.group.GroupChannel"&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span class="Apple-tab-span" style="background-color: #fff2cc; white-space: pre;"&gt;&lt;span style="color: #20124d;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;                     &lt;/span&gt;&amp;lt;Membership className="org.apache.catalina.tribes.membership.McastService"&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;span class="Apple-tab-span" style="color: #20124d; white-space: pre;"&gt;                                            &lt;/span&gt;&lt;span style="color: #20124d;"&gt;address="&lt;/span&gt;&lt;b&gt;&lt;span style="color: #4c1130;"&gt;228.0.0.4&lt;/span&gt;&lt;/b&gt;&lt;span style="color: #20124d;"&gt;"&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;span class="Apple-tab-span" style="color: #20124d; white-space: pre;"&gt;                                            &lt;/span&gt;&lt;span style="color: #20124d;"&gt;port="&lt;/span&gt;&lt;b&gt;&lt;span style="color: #4c1130;"&gt;45564&lt;/span&gt;&lt;/b&gt;&lt;span style="color: #20124d;"&gt;"&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;                                            &lt;/span&gt;frequency="500"&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;                                            &lt;/span&gt;dropTime="3000"/&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;                     &lt;/span&gt;&amp;lt;Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter"&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;                       &lt;/span&gt;&amp;lt;Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;                     &lt;/span&gt;&amp;lt;/Sender&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span class="Apple-tab-span" style="background-color: #fff2cc; white-space: pre;"&gt;&lt;span style="color: #20124d;"&gt;   &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;                      &lt;/span&gt;&amp;lt;Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;                                       &lt;/span&gt;address="auto"&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;                                       &lt;/span&gt;port="&lt;/span&gt;&lt;span style="background-color: #fff2cc; color: #4c1130;"&gt;&lt;b&gt;4000&lt;/b&gt;&lt;/span&gt;&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;"&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;                                       &lt;/span&gt;autoBind="100"&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;                                      &lt;/span&gt;selectorTimeout="5000"&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;                                      &lt;/span&gt;maxThreads="6"/&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span class="Apple-tab-span" style="background-color: #fff2cc; white-space: pre;"&gt;&lt;span style="color: #20124d;"&gt;     &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;                   &lt;/span&gt;&amp;lt;Interceptor &amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span class="Apple-tab-span" style="background-color: #fff2cc; white-space: pre;"&gt;&lt;span style="color: #20124d;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;                   &lt;/span&gt;&amp;lt;Interceptor&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span class="Apple-tab-span" style="background-color: #fff2cc; white-space: pre;"&gt;&lt;span style="color: #20124d;"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;          &lt;/span&gt;&amp;lt;/Channel&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;span class="Apple-tab-span" style="background-color: #fff2cc; white-space: pre;"&gt;&lt;span style="color: #20124d;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;       &lt;/span&gt;&amp;lt;Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter=""/&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-tab-span" style="background-color: #fff2cc; white-space: pre;"&gt;&lt;span style="color: #20124d;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;       &lt;/span&gt;&amp;lt;Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-tab-span" style="background-color: #fff2cc; white-space: pre;"&gt;&lt;span style="color: #20124d;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;      &lt;/span&gt;&amp;lt;ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-tab-span" style="background-color: #fff2cc; white-space: pre;"&gt;&lt;span style="color: #20124d;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;       &lt;/span&gt;&amp;lt;ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-tab-span" style="background-color: #fff2cc; white-space: pre;"&gt;&lt;span style="color: #20124d;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&amp;lt;/Cluster&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="background-color: #d0e0e3;"&gt;&lt;b&gt;Check my sample &lt;a href="https://github.com/ramkicse/tomcat-clustering-session-replication-/blob/master/instance-1/conf/server.xml" target="_blank"&gt;conf/server.xml&lt;/a&gt; file (for reference)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
here most of the code are &amp;nbsp;boiler plate code. just copy and paste. if we need we can customize. for example we can change the multicat address and port number.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&amp;lt;Manager className="org.apache.catalina.ha.session.DeltaManager"/&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
here&amp;nbsp;Manager tag define the delta manager. Delta manager means&amp;nbsp;replicate&amp;nbsp;to all instances.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-tab-span" style="color: #20124d; white-space: pre;"&gt; &lt;/span&gt;&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&amp;lt;Channel className="org.apache.catalina.tribes.group.GroupChannel"&amp;gt;&lt;/span&gt;&lt;br /&gt;
Tomcat Clustering use the &lt;span style="background-color: #d9ead3;"&gt;Apache Tribes communication framework&lt;/span&gt;. &amp;nbsp;This group commnication&amp;nbsp;framework&amp;nbsp;is responsible for dynamic&amp;nbsp;membership&amp;nbsp;(using&amp;nbsp;multicast) , send and&amp;nbsp;receive&amp;nbsp;the session delta information using&amp;nbsp;uni-cast&amp;nbsp;(normal TCP connection).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&amp;lt;Membership className="org.apache.catalina.tribes.membership.McastService"&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;span class="Apple-tab-span" style="color: #20124d; white-space: pre;"&gt;                                            &lt;/span&gt;&lt;span style="color: #20124d;"&gt;address="&lt;/span&gt;&lt;b&gt;&lt;span style="color: #4c1130;"&gt;228.0.0.4&lt;/span&gt;&lt;/b&gt;&lt;span style="color: #20124d;"&gt;"&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;span class="Apple-tab-span" style="color: #20124d; white-space: pre;"&gt;                                            &lt;/span&gt;&lt;span style="color: #20124d;"&gt;port="&lt;/span&gt;&lt;b&gt;&lt;span style="color: #4c1130;"&gt;45564&lt;/span&gt;&lt;/b&gt;&lt;span style="color: #20124d;"&gt;"&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;                                            &lt;/span&gt;frequency="500"&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;                                            &lt;/span&gt;dropTime="3000"/&amp;gt;&lt;/span&gt;&lt;br /&gt;
This is Membership definition. here address is multicast address. we can pick any address from Class D address range (224.0.0.0 to 239.255.255.255)and any port number.&lt;br /&gt;
&lt;br /&gt;
Each and every tomcat send the heart beat signal to multicast address in&amp;nbsp;periodic&amp;nbsp;(&lt;span style="background-color: #d9ead3;"&gt;&lt;b&gt;frequency&lt;/b&gt;&lt;/span&gt;) interval. all other tomcat whose joined the multicast address they can&amp;nbsp;receive&amp;nbsp;these signals and add the membership to the cluster. if heat beat signal is not&amp;nbsp;revive&amp;nbsp;some&amp;nbsp;particular&amp;nbsp;interval&amp;nbsp;(&lt;span style="background-color: #d9ead3;"&gt;&lt;b&gt;dropTime&lt;/b&gt;&lt;/span&gt;) from any one of the tomcat, then we need to consider that tomcat is failed.&lt;br /&gt;
&lt;br /&gt;
&lt;b style="background-color: #fce5cd;"&gt;Note:-&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;All tomcat instances which is part of the clustering, &lt;span style="background-color: #d9ead3;"&gt;&lt;b&gt;should have same&amp;nbsp;multicast&amp;nbsp;address and port number.&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&amp;lt;Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter"&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;                       &lt;/span&gt;&amp;lt;Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;                     &lt;/span&gt;&amp;lt;/Sender&amp;gt;&lt;/span&gt;&lt;br /&gt;
here sender use the PooledParallelSender have pooled connections to use the send the session information&amp;nbsp;concurrently. so its speedup the session replication process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-tab-span" style="color: #20124d; white-space: pre;"&gt; &lt;/span&gt;&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&amp;lt;Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;                                       &lt;/span&gt;address="auto"&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;                                       &lt;/span&gt;port="&lt;/span&gt;&lt;span style="background-color: #fff2cc; color: #4c1130;"&gt;&lt;b&gt;4000&lt;/b&gt;&lt;/span&gt;&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;"&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;                                       &lt;/span&gt;autoBind="100"&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;                                      &lt;/span&gt;selectorTimeout="5000"&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;                                      &lt;/span&gt;maxThreads="6"/&amp;gt;&lt;/span&gt;&lt;br /&gt;
here we define which port Receiver can bind and used for receiving the session replicate information. here two properties are important. address and port. here address is ur system IP address and port is any unused port. here&lt;span style="background-color: #fce5cd;"&gt; address="auto"&lt;/span&gt; its automatically pick the system IP address.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
we have some interceptor&lt;br /&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;TcpFailureDetector&amp;nbsp;&lt;/span&gt;-Its ensure that instance are dead. In some case&amp;nbsp;multicast&amp;nbsp;messages are delayed, all tomcat instances are think about that tomcat is dead. but this interceptor to make tcp unicast to failed tomcat and ensure that instances is actually failed or not&lt;br /&gt;
&lt;br /&gt;
another important&amp;nbsp;listener&amp;nbsp;is&amp;nbsp;&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;JvmRouteSessionIDBinderListener,&lt;/span&gt;&amp;nbsp;we talk&amp;nbsp;about&amp;nbsp;later&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;h3 style="text-align: left;"&gt;
&lt;span style="color: #cc0000;"&gt;3. Enable the Web Application as distributable&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #cc0000;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&amp;nbsp; &amp;nbsp;We need to&amp;nbsp;make&amp;nbsp;the our web application distribuable. its simple add&amp;nbsp;&amp;lt;distributable/&amp;gt; tag in web.xml file. In according to servlet specification&amp;nbsp;&amp;nbsp;&lt;b style="background-color: #d9ead3;"&gt;&amp;lt;distributable/&amp;gt; &lt;/b&gt;tag in web.xml mention that any container to consider this application can work in&amp;nbsp;distributed&amp;nbsp;environment.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="background-color: #fce5cd;"&gt;&lt;b&gt;Note:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
All session in our web&amp;nbsp;application&amp;nbsp;must me serializable.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Do these steps to all tomcat instances and start the tomcat and httpd server. check my configuration in my &lt;a href="https://github.com/ramkicse/tomcat-clustering-session-replication-" target="_blank"&gt;github repo&lt;/a&gt;&amp;nbsp;or get as &lt;a href="https://github.com/ramkicse/tomcat-clustering-session-replication-/archive/master.zip" target="_blank"&gt;ZIP&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-ZfR6DhJ_vpg/UKsf-Dgx5CI/AAAAAAAACrQ/ly1ToOlibr0/s1600/session-repicate1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="231" src="http://1.bp.blogspot.com/-ZfR6DhJ_vpg/UKsf-Dgx5CI/AAAAAAAACrQ/ly1ToOlibr0/s400/session-repicate1.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
This is my configuration. all 3 tomcat instances are&amp;nbsp;configured&amp;nbsp;in delta manager and i deployed the distributed web&amp;nbsp;application. all tomcat use the&amp;nbsp;multicast&amp;nbsp;to maintain the membership.&lt;br /&gt;
&lt;br /&gt;
now client make the request and first tomcat process and create the session, then looks like this&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-H8t6z1PlfJk/UKsf4WH8oLI/AAAAAAAACrA/Ti25yR5i5Fw/s1600/session-replicate2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="227" src="http://4.bp.blogspot.com/-H8t6z1PlfJk/UKsf4WH8oLI/AAAAAAAACrA/Ti25yR5i5Fw/s400/session-replicate2.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
then tomcat 1 is responsible to replicate the session using&amp;nbsp;Apache&amp;nbsp;tribes group&amp;nbsp;communication&amp;nbsp;framework to replicate the session to all instances.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-lnVwldNtunU/UKsf5lA6mRI/AAAAAAAACrI/GcnN5qFlHaA/s1600/session-replicate3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="226" src="http://3.bp.blogspot.com/-lnVwldNtunU/UKsf5lA6mRI/AAAAAAAACrI/GcnN5qFlHaA/s400/session-replicate3.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
now all tomcat instance have exact copy of the session. so if tomcat 1 crashed or shutdown, then any other tomcat still can&amp;nbsp;process&amp;nbsp;the request [see the video below]&lt;br /&gt;
&lt;br /&gt;
We used session&amp;nbsp;affinity&amp;nbsp;like&amp;nbsp;&lt;a href="http://www.ramkitech.com/2012/10/tomcat-clustering-series-part-2-session.html" target="_blank"&gt;previous&amp;nbsp;post&lt;/a&gt;. based on that cookie id&amp;nbsp;contain&amp;nbsp;the tomcat name (worker name). so when first tomcat1 return the session id end with tomcat1. but when tomcat 1 is failed and tomcat 2 take the responsible for all further request. but session id still contain the tomcat1. so its makes the load balancer&amp;nbsp;difficult.&amp;nbsp;because&amp;nbsp;tomcat1 is down. and load balancer pick any other tomcat. but&amp;nbsp;actually&amp;nbsp;tomcat2 takes the&amp;nbsp;responsible. so we need to reflect these changes in session id. &lt;br /&gt;
&lt;span style="background-color: #fff2cc; color: #20124d;"&gt;JvmRouteSessionIDBinderListener&lt;/span&gt;&amp;nbsp; take care to change the client session id to tomcat2 when&amp;nbsp;failure&amp;nbsp;is&amp;nbsp;occurred&amp;nbsp; so load balancer redirect to tomcat2 without confusing.&lt;br /&gt;
&lt;br /&gt;
Check&amp;nbsp;the &lt;a href="https://github.com/ramkicse/tomcat-clustering-session-replication-" target="_blank"&gt;git hub&lt;/a&gt; for all configuration files and tomcat clustering setup is available. or u can download as &lt;a href="https://github.com/ramkicse/tomcat-clustering-session-replication-/archive/master.zip" target="_blank"&gt;ZIP&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style="text-align: left;"&gt;
&lt;span style="color: #660000;"&gt;Reference:&lt;/span&gt;&lt;/h3&gt;
&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;&lt;a href="http://tomcat.apache.org/tomcat-7.0-doc/cluster-howto.html" target="_blank"&gt;Apache Tomcat Cluster Documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;span style="color: #660000; font-family: Times, Times New Roman, serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;span style="color: #660000; font-family: Times, Times New Roman, serif;"&gt;Screen&amp;nbsp;Cast:&lt;/span&gt;&lt;/h2&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="360" src="http://www.youtube.com/embed/cYBdaeNeXbY" width="700"&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=JRBoYZDNAJw:2FkD25Kw0GI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=JRBoYZDNAJw:2FkD25Kw0GI:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=JRBoYZDNAJw:2FkD25Kw0GI:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?i=JRBoYZDNAJw:2FkD25Kw0GI:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=JRBoYZDNAJw:2FkD25Kw0GI:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ramki/feeds/~4/JRBoYZDNAJw" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ramki/feeds/~3/JRBoYZDNAJw/tomcat-clustering-series-part-3-session.html</link><author>noreply@blogger.com (Rama krishnnan E P)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-ZfR6DhJ_vpg/UKsf-Dgx5CI/AAAAAAAACrQ/ly1ToOlibr0/s72-c/session-repicate1.png" height="72" width="72" /><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /><feedburner:origLink>http://www.ramkitech.com/2012/11/tomcat-clustering-series-part-3-session.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-1342436239924206221</guid><pubDate>Tue, 30 Oct 2012 08:48:00 +0000</pubDate><atom:updated>2012-11-21T14:45:26.642+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">multiple_instances</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">mod_jk</category><category domain="http://www.blogger.com/atom/ns#">tomcat clustering</category><category domain="http://www.blogger.com/atom/ns#">load balancer</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><title>Tomcat Clustering Series Part 2 : Session Affinity Load Balancer</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
Hi this second part of the&amp;nbsp;&lt;a href="http://www.ramkitech.com/search/label/tomcat%20clustering" target="_blank"&gt;Tomcat Clustering Series&lt;/a&gt;. In my&lt;a href="http://www.ramkitech.com/2012/10/tomcat-clustering-series-simple-load.html" target="_blank"&gt; first part&lt;/a&gt; we discuss about how to setup simple load balancer. and we seen how load balancer distribute the request to tomcat instance in round robin fashion.&lt;span style="color: #660000;"&gt; &lt;b style="background-color: #fff2cc;"&gt;[Check the video below for better understanding]&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
In this post we discuss about what is the problem is occur in simple load balancer when we introduce sessions in our web application. and we will see how to resolve this issue.&lt;br /&gt;
&lt;br /&gt;
Its&amp;nbsp;continuation&amp;nbsp;of my &lt;a href="http://www.ramkitech.com/2012/10/tomcat-clustering-series-simple-load.html" target="_blank"&gt;first part&lt;/a&gt; of this series. so kindly go read my &lt;a href="http://www.ramkitech.com/2012/10/tomcat-clustering-series-simple-load.html" target="_blank"&gt;first part&lt;/a&gt; then continue here.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #660000; font-size: large;"&gt;How Session works in Servlet/Tomcat?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Before going into problem, let see the &lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;session management in Tomcat&lt;/b&gt;&lt;/span&gt;.&lt;br /&gt;
If any if the page/servlet&amp;nbsp;create the session&amp;nbsp;then Tomcat create the Session Object and&amp;nbsp;attached&amp;nbsp;into group of session (HashMap kind structure) and that session can identify using session-id, its just random number generated through any one of the hash algorithm. then respond to client with cookie header field. That cookie header field are key value pair. so tomcat create jsessioid is the key and random session-id is the value.&lt;br /&gt;
&lt;br /&gt;
Once response reached to client (Web Browser) its update the cookie value. If already exist, then its overrides the cookie value. Then all further communication browser send the cookie attached with&amp;nbsp;request&amp;nbsp;to that server.&lt;br /&gt;
&lt;br /&gt;
HTTP is stateless protocol. so server can't find the client session usual way. so server reads the header of the request and extract the cookie value and server got the Random session-id. then it search through group of session maintained by the tomcat. (It&amp;nbsp;usually&amp;nbsp;hash-map). then tomcat got perfect Session of that particular client (Web Browser).&lt;br /&gt;
&lt;br /&gt;
If client cookie value doesn't match with group of sessions then tomcat create the completely new session and send the new cookie to browser. then browser update it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
this &lt;b&gt;&lt;span style="color: #990000;"&gt;index.jsp&lt;/span&gt;&lt;/b&gt; code to deploy all tomcat instances&lt;br /&gt;
&lt;pre class="java" name="code"&gt;&amp;lt;%@page import="java.util.ArrayList"%&amp;gt;
&amp;lt;%@page import="java.util.Date"%&amp;gt;

&amp;lt;%@page import="java.util.List"%&amp;gt;
&amp;lt;%@page contentType="text/html" pageEncoding="UTF-8"%&amp;gt;

&lt;html&gt;
    &lt;head&gt;
        
        &lt;title&gt;JSP Page&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
&lt;span style="color: blue; font-size: small;"&gt;
        Instance 1 


        &lt;/span&gt;
       
        &lt;hr /&gt;

        &lt;span style="color: #cc0000; font-size: small;"&gt;
         

        Session Id : &amp;lt;%=request.getSession().getId()%&amp;gt; 

        Is it New Session : &amp;lt;%=request.getSession().isNew()%&amp;gt;

        Session Creation Date : &amp;lt;%=new Date(request.getSession().getCreationTime())%&amp;gt;

        Session Access Date : &amp;lt;%=new Date(request.getSession().getLastAccessedTime())%&amp;gt;


        &lt;/span&gt;
        &lt;b&gt;Cart List &lt;/b&gt;

        &lt;hr /&gt;
        
        
        &lt;ul&gt;
        &amp;lt;%

                String bookName = request.getParameter("bookName");
                List&lt;string&gt; listOfBooks = (List&lt;string&gt;) request.getSession().getAttribute("Books");

                if (listOfBooks == null) {
                    listOfBooks = new ArrayList&lt;string&gt;();
                    request.getSession().setAttribute("Books", listOfBooks);
                }
                if (bookName != null) {
                    listOfBooks.add(bookName);
                    request.getSession().setAttribute("Books", listOfBooks);
                }


                for (String book : listOfBooks) {
                    out.println("
&lt;li&gt;"+book + "&lt;/li&gt;
");
                }
            
        %&amp;gt;
        &lt;/string&gt;&lt;/string&gt;&lt;/string&gt;&lt;/ul&gt;
&lt;hr /&gt;
        &lt;form action="index.jsp" method="post"&gt;
            Book Name &lt;input name="bookName" type="text" /&gt;

            &lt;input type="submit" value="Add to Cart" /&gt;
        &lt;/form&gt;
&lt;hr /&gt;
    &lt;/body&gt;
&lt;/html&gt;

&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #660000; font-size: large;"&gt;&lt;b&gt;What is the Problem In Simple Load Balancer?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;If we deploy the web application, in which its used the session then actual problem is&amp;nbsp;occurred.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-9nG82vXSuFw/UHUS9R5_9pI/AAAAAAAACmw/QMlhCCwySiw/s1600/tomcat_simple_load_balancer.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="328" src="http://2.bp.blogspot.com/-9nG82vXSuFw/UHUS9R5_9pI/AAAAAAAACmw/QMlhCCwySiw/s640/tomcat_simple_load_balancer.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;b&gt;&lt;span style="color: #660000; font-size: large;"&gt;I&amp;nbsp;describe with sequence&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #660000; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;1. User request one web page, in that web page its used sessions (like shopping cart).&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;2. Load balancer intercept the request and use the round robin fashion its send to one of the tomcat. suppose this time its send to tomcat1.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;3. tomcat1 create the session and respond with cookie header to client.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;4. load balancer just act as relay. its send back to client.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;5. next time user request again the shopping cart to server. this time user send the cookie header also&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;6.Load balancer intercept the request and use the round robin fashion its send to one of the tomcat. this time its send to tomcat2.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;7. Tomcat 2 receive the request and extract the session-id. and this session id is doesn't match with their managed session. because this session is&amp;nbsp;available&amp;nbsp;only in tomcat1. so tomcat 2 is create the new session &amp;nbsp;and send new cookie to client&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;8. Client&amp;nbsp;receive&amp;nbsp;the response and update the cookie(Its overwrite the old cookie).&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;9. Client send one more time to request that page and send the cookie to server.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;10.&amp;nbsp;Load balancer intercept the request and use the round robin fashion its send to one of the tomcat. this time its send to tomcat3.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;11.&amp;nbsp;Tomcat 3 receive the request and extract the session-id. and this session id is doesn't match with their managed session. because this session is&amp;nbsp;available&amp;nbsp;only in tomcat2. so tomcat3 is create the new session &amp;nbsp;and send new cookie to client&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;12. Client&amp;nbsp;receive&amp;nbsp;the response and update the cookie.&lt;/span&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;(Its overwrite the old cookie).&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;13. Client send one more time to request that page and send the cookie to server.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;14.&amp;nbsp;Load balancer intercept the request and use the round robin fashion its send to one of the tomcat. this time its send to tomcat1.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;15.&amp;nbsp;Tomcat 1 receive the request and extract the session-id. and this session id is doesn't match with their managed session. because client session id is updated by tomcat 3 last time. so even though tomcat 1 have one session object created by this client. but client session id is wrong.so tomcat1 is create the new session &amp;nbsp;and send new cookie to client (for more info watch the video below)&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;16. Client&amp;nbsp;receive&amp;nbsp;the response and update the cookie.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
this&amp;nbsp;sequence&amp;nbsp;is&amp;nbsp;continue ...&lt;br /&gt;
&lt;br /&gt;
as the result every request one session is created. instead of&amp;nbsp;continue&amp;nbsp;with old one.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here &lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;root cause is Load&amp;nbsp;balancer&lt;/b&gt;&lt;/span&gt;. If load balancer redirect the request&amp;nbsp;correctly&amp;nbsp;then this problem is fixed. but how load balancer know in advance about this client before is processed by particular tomcat.&lt;br /&gt;
HTTP is stateless protocol. so HTTP&amp;nbsp;doesn't&amp;nbsp;help this situation. and other information is jsessionid cookie. its good but its just random value. so we can't take decision based on this random value.&lt;br /&gt;
ex:&lt;br /&gt;
&lt;div style="text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="header-name" style="box-sizing: border-box; display: inline-block; font-family: 'Lucida Grande', sans-serif; font-size: 11px; margin-right: 0.5em; vertical-align: top; white-space: pre-wrap;"&gt;
&lt;b style="background-color: #fff2cc;"&gt;Cookie: &lt;span style="font-family: 'dejavu sans mono', monospace;"&gt;JSESSIONID=40025608F7B50E42DFA2785329079227&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style="text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 id="dqx7lbg_sessionaffinity"&gt;
&lt;span style="color: #660000; font-size: large;"&gt;
Session affinity/Sticky Session&lt;/span&gt;&lt;/h3&gt;
&lt;div&gt;
&lt;span style="background-color: white;"&gt;Session affinity overrides the load-balancing algorithm by directing all requests in a session to a specific tomcat server. so when we setup the session affinity our problem is solved. but how to setup because session values are random value. so we need to generate the session value some how identify the which tomcat generate response.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: white;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: white; color: #990000; font-size: large;"&gt;&lt;b&gt;jvmRoute&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: white;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: white;"&gt;Tomcat configuration file (server.xml) caontain &amp;nbsp;&amp;lt;Engine&amp;gt; tag have jvmRoute property for this purpose. so edit the config file and update the &amp;lt;Engine &amp;gt; tag like this&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: white;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;&lt;span style="color: #990000;"&gt;&amp;lt;Engine name="Catalina" defaultHost="localhost“ &lt;/span&gt;&lt;span style="color: blue;"&gt;jvmRoute=“tomcat1”&lt;/span&gt;&lt;span style="color: #990000;"&gt; &amp;gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: white;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: white;"&gt;here we mention &lt;/span&gt;&lt;b style="background-color: #fff2cc;"&gt;jvmRoute="tomcat1"&lt;/b&gt;&lt;span style="background-color: white;"&gt; here tomcat1 is worker name of this tomcat. check the workers.properties file in&lt;/span&gt;&lt;a href="http://www.ramkitech.com/2012/10/tomcat-clustering-series-simple-load.html" style="background-color: white;" target="_blank"&gt; last post&lt;/a&gt;&lt;span style="background-color: white;"&gt;.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: white;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: white;"&gt;Add this line to all tomcat&amp;nbsp;instances&amp;nbsp;&lt;/span&gt;&lt;span style="background-color: #d9ead3;"&gt;&lt;b&gt;conf/server.xml&lt;/b&gt;&lt;/span&gt;&lt;span style="background-color: white;"&gt; file and change the jvmRoute value according to workers name and restart the tomcat instances.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: white;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: white;"&gt;Now all tomcat generate the session-id pattern like this&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&amp;lt;Random Value like before&amp;gt;.&amp;lt;jvmRoute value&amp;gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
ex: tomcat1 generate the session id &amp;nbsp;like&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;&lt;span style="font-family: 'Lucida Grande', sans-serif; font-size: 11px; text-align: center; white-space: pre-wrap;"&gt;Cookie:&lt;/span&gt;&lt;span style="font-family: 'dejavu sans mono', monospace; font-size: 11px; text-align: center; white-space: pre-wrap;"&gt;JSESSIONID=40025608F7B50E42DFA2785329079227.tomcat1&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ol class="children expanded" style="-webkit-padding-start: 12px; background-color: white; box-sizing: border-box; cursor: default; font-family: 'Lucida Grande', sans-serif; font-size: 11px; list-style-type: none; margin: 0px; min-width: 100%; padding: 2px 6px !important; position: relative; text-align: center;"&gt;
&lt;li style="box-sizing: border-box; margin-bottom: 1px; margin-left: -2px; margin-top: 1px; padding: 0px 0px 0px 14px; text-align: center; white-space: nowrap; word-wrap: break-word;" title=""&gt;
&lt;/li&gt;
&lt;li&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div style="text-align: center;"&gt;
&lt;span style="background-color: white;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
here tail have which tomcat generate the session. so load balancer easily find out to where we need to&amp;nbsp;delegate&amp;nbsp;the request. in this case its tomcat1.&lt;br /&gt;
&lt;br /&gt;
so update all tomcat instances conf/server.xml file to add the jvmRoute property to appropriate worker name values. and restart the instances. all problem is fixed and entire load balance works fine even session based application.&lt;br /&gt;
&lt;br /&gt;
&lt;b style="background-color: #fff2cc;"&gt;but there is still one drawback&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
if 5 user acessing the website. In session affinity is setup. here&lt;br /&gt;
&lt;br /&gt;
tomcat 1 serves 2 user,&lt;br /&gt;
&lt;div&gt;
tomcat 2 serves 2 user,&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
tomcat 3 serves 1 user, &amp;nbsp;then suddenly one of instance is failed, then what happen?&lt;br /&gt;
&lt;br /&gt;
suppose instance 1 (tomcat1) is failed, then those 2 users lost their session. but their request are redirect to one of the remaining tomcat instances (tomcat2,tomcat3). so they still access the web page. but they lost&amp;nbsp;previous&amp;nbsp;sessions. this is one of the draw back. but its compare to last post load balancer. its works in session based web application also.&lt;br /&gt;
&lt;br /&gt;
next post we will see how to set up the session replication in load balancer.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #0c343d;"&gt;please share ur thoughts through comments.&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 style="text-align: left;"&gt;
Update :&amp;nbsp;Check&amp;nbsp;the Session Replication Process in&amp;nbsp;&lt;a href="http://www.ramkitech.com/2012/11/tomcat-clustering-series-part-3-session.html" target="_blank"&gt;Third&amp;nbsp;Part&lt;/a&gt; of this Series&lt;/h4&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;span style="color: #660000; font-size: large;"&gt;&lt;b&gt;Screen Cast:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="360" src="http://www.youtube.com/embed/-9C2ZtdAAFY?theme=light" width="640"&gt;&lt;/iframe&gt;

&lt;/div&gt;
&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=1Q2YhkZJ3Yc:fGL2bCSgmcQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=1Q2YhkZJ3Yc:fGL2bCSgmcQ:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=1Q2YhkZJ3Yc:fGL2bCSgmcQ:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?i=1Q2YhkZJ3Yc:fGL2bCSgmcQ:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=1Q2YhkZJ3Yc:fGL2bCSgmcQ:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ramki/feeds/~4/1Q2YhkZJ3Yc" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ramki/feeds/~3/1Q2YhkZJ3Yc/tomcat-clustering-series-part-2-session.html</link><author>noreply@blogger.com (Rama krishnnan E P)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-9nG82vXSuFw/UHUS9R5_9pI/AAAAAAAACmw/QMlhCCwySiw/s72-c/tomcat_simple_load_balancer.png" height="72" width="72" /><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /><feedburner:origLink>http://www.ramkitech.com/2012/10/tomcat-clustering-series-part-2-session.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-9158320692799127009</guid><pubDate>Wed, 10 Oct 2012 07:57:00 +0000</pubDate><atom:updated>2013-04-12T11:17:39.227+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">multiple_instances</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">mod_jk</category><category domain="http://www.blogger.com/atom/ns#">tomcat clustering</category><category domain="http://www.blogger.com/atom/ns#">load balancer</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><title>Tomcat Clustering Series Part 1 : Simple Load Balancer</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
I am going to start new series of posts about &lt;a href="http://www.ramkitech.com/search/label/tomcat%20clustering" target="_blank"&gt;Tomcat clustering&lt;/a&gt;. In this first post we will see what is problem in normal deployment in only single machine, what is clustering and why is necessary and how to setup the simple load balancer with Apache httpd web server + Tomcat server cluster.&lt;b style="background-color: #fff2cc; color: #660000;"&gt;[Check the video for better understanding]&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #990000; font-size: large;"&gt;&lt;b&gt;Why need Clustering? (Tomcat Clustering)&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; In normal production servers are running in single machine. If&amp;nbsp;that's&amp;nbsp;machine may be failed due to crashed or hardware&amp;nbsp;defects or OutOfMemory&amp;nbsp;exception then&amp;nbsp;&amp;nbsp;our site can't access by anybody.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-GUoJCzHlkWE/UHUH8hMT85I/AAAAAAAAClw/td_6l_JLh0E/s1600/normal_deployment.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="205" src="http://1.bp.blogspot.com/-GUoJCzHlkWE/UHUH8hMT85I/AAAAAAAAClw/td_6l_JLh0E/s400/normal_deployment.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
so &lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;how to solve this problem?&lt;/b&gt;&lt;/span&gt;. to add more tomcat machine to collectively (group/cluster) run as a production server. (oppose&amp;nbsp;of single machine). Each tomcat has deployed the same web application. so any tomcat can process the client request. If one tomcat is failed, then other tomcat in the cluster to&amp;nbsp;proceeds&amp;nbsp;the request.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-pQLAYmjpO68/UHUKwW1g-bI/AAAAAAAACmE/FcRbf0PsSHY/s1600/tomcat_clustering.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="209" src="http://3.bp.blogspot.com/-pQLAYmjpO68/UHUKwW1g-bI/AAAAAAAACmE/FcRbf0PsSHY/s320/tomcat_clustering.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
Here one big problem is arrive. each tomcat instances are running in dedicated physical machine or many tomcat instances are running in single machine(Check my post about&lt;a href="http://www.ramkitech.com/2011/07/running-multiple-tomcat-instances-on.html" target="_blank"&gt; Running multiple tomcat instances in single machine&lt;/a&gt;). so each tomcat running on different port and may be in&amp;nbsp;&amp;nbsp;different IP.&lt;br /&gt;
&lt;br /&gt;
the problem is in client perspective, to which tomcat we need to make the request? because there are lots of tomcat part of clustering is running. each tomcat we need to make IP and Port combination. like&lt;br /&gt;
http://192.168.56.190:8080/ or&amp;nbsp;http://192.168.56.191:8181/&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-h8yCwF7-w1Q/UHUKyo8DLsI/AAAAAAAACmQ/CfsOnomRSSc/s1600/tomcat_how_to_access.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="176" src="http://1.bp.blogspot.com/-h8yCwF7-w1Q/UHUKyo8DLsI/AAAAAAAACmQ/CfsOnomRSSc/s640/tomcat_how_to_access.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
so how to solve this problem?&lt;br /&gt;
To add one server&amp;nbsp;in-front&amp;nbsp;of all tomcat clusters. to accept all the request and distribute to the cluster. so this server acts as a load balancer. There is lots of server is&amp;nbsp;available&amp;nbsp;with load balancing capability. here we are going to use&amp;nbsp;Apache&amp;nbsp;httpd web server as a load balancer. with mod_jk module.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-YoAJypnbcOs/UHUKzjI5GuI/AAAAAAAACmc/8oV7yfG7GN4/s1600/tomcat_load_balancer.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="272" src="http://1.bp.blogspot.com/-YoAJypnbcOs/UHUKzjI5GuI/AAAAAAAACmc/8oV7yfG7GN4/s640/tomcat_load_balancer.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
so now all clients to access the load balancer (Apache httpd web server) and don't bother about tomcat instances. so now ur URL is http://ramkitech.com/ (Apache&amp;nbsp;runs on port 80).&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #990000; font-size: large;"&gt;Apache httpd Web Server&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Here we are going to use Apache httpd web server as a Load Balancer. To provide the load balancing capability to Apache httpd server we need to include the either mod_proxy module or mod_jk module. here we are using mod_jk module.&lt;br /&gt;
&lt;br /&gt;
Before continuing this post check my &lt;a href="http://www.ramkitech.com/2012/03/virtual-host-apache-httpd-server-tomcat.html" target="_blank"&gt;old post (Virtual Host Apache httpd server)&lt;/a&gt; about How to install the Apache httpd server and mod_jk module. and how to configure the mod_jk.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #990000; font-size: large;"&gt;&lt;b&gt;How to setup the Simple Load Balancer&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;For simplicity purpose i going to run 3 tomcat instances in single machine(we can run on dedicated machine also) with Apache httpd web server. and single web application is deployed in all tomcat instances.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-9nG82vXSuFw/UHUS9R5_9pI/AAAAAAAACmw/QMlhCCwySiw/s1600/tomcat_simple_load_balancer.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="328" src="http://2.bp.blogspot.com/-9nG82vXSuFw/UHUS9R5_9pI/AAAAAAAACmw/QMlhCCwySiw/s640/tomcat_simple_load_balancer.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
here we use mod_jk module as the load balancer. by default its use the round robin algorithm to&amp;nbsp;distribute&amp;nbsp;the requests. now we need to configure the workers.properties file like &lt;a href="http://www.ramkitech.com/2012/03/virtual-host-apache-httpd-server-tomcat.html" target="_blank"&gt;virtual host concept in Apache httpd server.&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;worker.list=tomcat1,tomcat2,tomcat3&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style="background-color: #fff2cc;"&gt;worker.tomcat1.type=ajp13&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;worker.tomcat1.port=8009&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;worker.tomcat1.host=localhost&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style="background-color: #fff2cc;"&gt;worker.tomcat2.type=ajp13&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;worker.tomcat2.port=8010&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;worker.tomcat2.host=localhost&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style="background-color: #fff2cc;"&gt;worker.tomcat3.type=ajp13&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;worker.tomcat3.port=8011&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;worker.tomcat3.host=localhost&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
here i configure the 3 tomcat instances in&lt;span style="background-color: #d9ead3;"&gt; &lt;b&gt;workers.properties&lt;/b&gt;&lt;/span&gt; file. here type is ajp13 and port is ajp port (not http connector port) and host is IP address of tomcat instance machine.&lt;br /&gt;
&lt;br /&gt;
there are couple of special&amp;nbsp;workers&amp;nbsp;we need add into workers.properties file.&lt;br /&gt;
&lt;br /&gt;
First one is add load balancer worker, here the name is &amp;nbsp;balancer (u can put any name).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b style="background-color: #fff2cc;"&gt;worker.balancer.type=lb&lt;/b&gt;&lt;br /&gt;
&lt;b style="background-color: #fff2cc;"&gt;worker.balancer.balance_workers=tomcat1,tomcat2,tomcat3&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
here this worker &lt;i&gt;&lt;b&gt;type&lt;/b&gt;&lt;/i&gt; is lb, ie load balancer. its special type provide by load&amp;nbsp;balancer. and another property is&amp;nbsp;&lt;i&gt;&lt;b&gt;balance_workers&lt;/b&gt;&lt;/i&gt; to specify all tomcat instances like&amp;nbsp;tomcat1,tomcat2,tomcat3 (comma&amp;nbsp;separated)&lt;br /&gt;
&lt;br /&gt;
Second one, add the status worker, Its optional. but from this worker we can get&amp;nbsp;statistical&amp;nbsp;of load balancer.&lt;br /&gt;
&lt;br /&gt;
&lt;b style="background-color: #fff2cc;"&gt;worker.stat.type=status&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
here we use special type status.&lt;br /&gt;
&lt;br /&gt;
now we modify the&amp;nbsp;worker.list property.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;worker.list=balancer,stat&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
so from outside there are 2 workers are visible (balancer and stat). so all request comes to balancer. then balancer worker manage all tomcat instances.&lt;br /&gt;
&lt;br /&gt;
complete&lt;b&gt;&lt;u&gt;&lt;span style="color: #990000;"&gt; workers.properties&lt;/span&gt;&lt;/u&gt;&lt;/b&gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;worker.list=balancer,stat

worker.tomcat1.type=ajp13
worker.tomcat1.port=8009
worker.tomcat1.host=localhost

worker.tomcat2.type=ajp13
worker.tomcat2.port=8010
worker.tomcat2.host=localhost

worker.tomcat3.type=ajp13
worker.tomcat3.port=8011
worker.tomcat3.host=localhost


worker.balancer.type=lb
worker.balancer.balance_workers=tomcat1,tomcat2,tomcat3

worker.stat.type=status
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
Now workers.properties confiuration is finished. now we need to send the all request to balancer worker.&lt;br /&gt;
so modify the httpd.conf file of Apache httpd server&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;LoadModule    jk_module  modules/mod_jk.so

JkWorkersFile conf/workers.properties

JkLogFile     logs/mod_jk.log
JkLogLevel    emerg
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions     +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat     "%w %V %T"

JkMount  /status  stat
JkMount  /  balancer
&lt;/pre&gt;
&lt;br /&gt;
&lt;div&gt;
the above code is just boiler plate code. 1st line load the mod_jk module, 2nd line to&amp;nbsp;specified&amp;nbsp;the worker file (workers.properties file). all others are just logging purpose.&lt;br /&gt;
&lt;br /&gt;
The last 2 lines are important.&lt;br /&gt;
&lt;b style="background-color: #fff2cc;"&gt;JkMount &amp;nbsp;/status &amp;nbsp;stat&lt;/b&gt; &amp;nbsp; means any request to match the /status then that request forward to stat worker. Its status type worker. so its shows status of load balancer.&lt;br /&gt;
&lt;br /&gt;
&lt;b style="background-color: #fff2cc;"&gt;JkMount &amp;nbsp;/ &amp;nbsp;balancer&lt;/b&gt; this line matches all the request, so all request is forward to balancer worker. In balancer worker ist uses the round robin algorithm to distribuete the request to other tomcat instances.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
That's&amp;nbsp;it.&lt;br /&gt;
now access the load balancer from the browser. each and every request is&amp;nbsp;distribute&amp;nbsp;to 3 tomcat&amp;nbsp;instances. If one of the tomcat instances are failed then load balancer&amp;nbsp;dynamically&amp;nbsp;understand and stop to forward the request to&amp;nbsp;that&amp;nbsp;failed tomcat instances. Other tomcat instances are&amp;nbsp;continue&amp;nbsp;to work. If that failed tomcat is recovered from failed state to normal state then load balancer add to cluster and forward the request to that tomcat. (check the video)&lt;br /&gt;
&lt;br /&gt;
Here &lt;b style="background-color: #d9ead3;"&gt;&lt;span style="color: #660000;"&gt;big question is How Load balancer knows when one tomcat instance is failed or tomcat is just recovered&amp;nbsp;from failed state?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Ans : &lt;/b&gt;when one tomcat instance is failed, load balancer don't know about&amp;nbsp;that&amp;nbsp;instances is failed. so its try to forward the request to all tomcat instances. If load balancer try to forward the request to failed tomcat instance, its will not respond. so load balancer understand and marked the state as a failed and forward the same request to another tomcat instances. so client&amp;nbsp;perspective&amp;nbsp;we not feel one tomcat instances are failed. &lt;br /&gt;
&lt;br /&gt;
when tomcat instances recovered from failed state. that time also load balancer don't know that tomcat is ready for processing. Its still marked the state is failed. In&amp;nbsp;periodic&amp;nbsp;interval&amp;nbsp;load balancer checks the health status of all tomcat instances. (by default 60 sec). after checking health status then only load balancer came to know that tomcat&amp;nbsp;instance&amp;nbsp;is ready. and its update the status is OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
please share ur thoughts through comments.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #990000; font-size: large;"&gt;&lt;u&gt;&lt;b&gt;Video :&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;/div&gt;
&lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="480" src="http://www.youtube.com/embed/9gtpyqhd-NI" width="700"&gt;&lt;/iframe&gt;

&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=cTDOk0QMQSU:_MbOD7dGENA:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=cTDOk0QMQSU:_MbOD7dGENA:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=cTDOk0QMQSU:_MbOD7dGENA:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?i=cTDOk0QMQSU:_MbOD7dGENA:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=cTDOk0QMQSU:_MbOD7dGENA:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ramki/feeds/~4/cTDOk0QMQSU" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ramki/feeds/~3/cTDOk0QMQSU/tomcat-clustering-series-simple-load.html</link><author>noreply@blogger.com (Rama krishnnan E P)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-GUoJCzHlkWE/UHUH8hMT85I/AAAAAAAAClw/td_6l_JLh0E/s72-c/normal_deployment.png" height="72" width="72" /><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /><feedburner:origLink>http://www.ramkitech.com/2012/10/tomcat-clustering-series-simple-load.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-113471435826741420</guid><pubDate>Wed, 12 Sep 2012 08:06:00 +0000</pubDate><atom:updated>2013-04-12T11:18:40.504+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">charts</category><category domain="http://www.blogger.com/atom/ns#">iReport</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">JasperReports</category><title>Integrate Chart Image into Jasper Report Part - 2</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
In my previous post we discussed &lt;a href="http://www.ramkitech.com/2012/09/integrate-charts-in-jasper-reports-jsf.html" target="_blank"&gt;how to&amp;nbsp;Integrate&amp;nbsp;the Charts into Jasper Reports&lt;/a&gt;&amp;nbsp;using JFreeChart API in Jasper Report. In this post there is another way to&amp;nbsp;embeds&amp;nbsp;the charts into Jasper Reports. This method, we need to generate/create the chart using any 3rd party Java Lib and convert into Image Object or stored into&amp;nbsp;File-system, then just insert the Image into Jasper Report. here no need to use chart&amp;nbsp;functionality&amp;nbsp;in Jasper Report. because these chart are&amp;nbsp;limited&amp;nbsp;functionality.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #990000; font-size: large;"&gt;&lt;b&gt;Steps:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;Create the chart using any Java libraries&lt;/li&gt;
&lt;li&gt;Convert the Chart into BufferedImage or Stored into files&lt;/li&gt;
&lt;li&gt;pass the Image into Jasper Report.&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;span style="color: #cc0000;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style="color: #cc0000;"&gt;&lt;b&gt;1. Create the chart using any Java libraries&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;In this step we going to create the chart. here i m using &lt;a href="http://jopenchart.sourceforge.net/" target="_blank"&gt;jopenchart&lt;/a&gt; Java library to create the chart. In their website &lt;a href="http://jopenchart.sourceforge.net/tutorial.html" target="_blank"&gt;tutorial section&lt;/a&gt; contain some sample codes. so i used these codes. and download the jopenchart lib from &lt;a href="http://prdownloads.sourceforge.net/jopenchart/charting-0.94.jar" target="_blank"&gt;here&lt;/a&gt;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #cc0000;"&gt;2. Convert the chart into&amp;nbsp;BufferedImage or Stored into files&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; In jopenchart have the&amp;nbsp;in-build&amp;nbsp;function for store chart into the file.&lt;br /&gt;
ChartEncoder.createPNG(new FileOutputStream(System.getProperty("user.home") + "/chat.png"), c);&lt;br /&gt;
and if u want into in-memory Image object then use render() method.&lt;br /&gt;
&lt;pre class="java" name="code"&gt;BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
DefaultChart chart = ....;
Graphics2D gd=bi.createGraphics();
chart.render(gd);
&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
In above code we create empty BufferedImage object. the get the Graphics2D object from the BufferedImage and pass the&amp;nbsp;Graphics2D into chart render() method. so when render() method is called, the chart is write into BufferedImage object.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #cc0000;"&gt;3. Pass the Image into Jasper Report&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; We need to create the Jasper Report. this time we are not using chart function in Jasper reports. we using Image component of jasperreport. We have 2 options are there, pass the Image Object or Pass the Path String object where image is stored in File-system. here first i m using Image object.&lt;br /&gt;
&lt;br /&gt;
we use parameter to pass into jasper report. so first create the new Parameter in Jasper Report and&amp;nbsp;named "chartImage" and Parameter Class "java.lang.Object".&amp;nbsp; drag the Image Component and set the properties. Image Expression and Expression Class like&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Image Expression == &amp;gt; &amp;nbsp;$P{chartImage}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Expression Class &amp;nbsp;== &amp;gt;&amp;nbsp;java.awt.Image&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-blQh4fe8Yzo/UFA91t8YnUI/AAAAAAAAClY/CeigA9_RD1A/s1600/image_property.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="85" src="http://2.bp.blogspot.com/-blQh4fe8Yzo/UFA91t8YnUI/AAAAAAAAClY/CeigA9_RD1A/s400/image_property.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
If we use stored Image File then change the Parameter class to&amp;nbsp;java.lang.String and Image Expression Class to&amp;nbsp;java.lang.String.&lt;br /&gt;
&lt;br /&gt;
here Image Expression class is decided the Jasper Report. how we add the Image. If u put "java.awt.Image" as a Expression class then we are passing the Image object. and jasper report can understand. If u mention "java.lang.String" then we pass as String that pointing to Image file. (png,jpg,gif,..).&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #990000;"&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;u&gt;DemoBean.java&lt;/u&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;@ManagedBean
@SessionScoped
public class DemoBean {

    int width = 640;
    int height = 480;
    BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

    public DemoBean() {
        int[] quadr = {0, 1, 4, 9, 16, 25, 36};
        int[] exp = {1, 2, 4, 8, 16, 32, 64};
        double[] columns = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0};

        // Creating a data set array
        DefaultDataSet[] ds = new DefaultDataSet[3];

        // Filling all DataSets
        ds[0] = new DefaultDataSet(ChartUtilities.transformArray(new int[]{0, 6}),
                ChartUtilities.transformArray(new double[]{0.0, 6.0}),
                CoordSystem.FIRST_YAXIS,
                "Linear Growth");

        ds[1] = new DefaultDataSet(ChartUtilities.transformArray(quadr),
                ChartUtilities.transformArray(columns),
                CoordSystem.FIRST_YAXIS,
                "Quadratic Growth");

        ds[2] = new DefaultDataSet(ChartUtilities.transformArray(exp),
                ChartUtilities.transformArray(columns),
                CoordSystem.FIRST_YAXIS,
                "Exponential Growth");

        String title = "Growth Factor Comparison";



        DefaultChartDataModel data = new DefaultChartDataModel(ds);

        data.setAutoScale(true);

        DefaultChart c = new DefaultChart(data, title, DefaultChart.LINEAR_X_LINEAR_Y);

          c.addChartRenderer(new LineChartRenderer(c.getCoordSystem(),data), 1);

        c.setBounds(new Rectangle(0, 0, width, height));
        Graphics2D gd=bi.createGraphics();
        c.render(gd);

//      /*  if ur using Image file then use these code */
//        try {
//            ChartEncoder.createPNG(new FileOutputStream(System.getProperty("user.home") + "/chart.png"), c);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }


    }

    public String pdf() throws JRException, IOException {

       
        String reportPath = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/reports/Charts.jasper");

        Map parameter = new HashMap();
        parameter.put("chartImage", bi);

        JasperPrint jasperPrint = JasperFillManager.fillReport(reportPath, parameter, new JREmptyDataSource(1));
        HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
        httpServletResponse.addHeader("Content-disposition", "attachment; filename=report.pdf");
        ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream();
        JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream);
        FacesContext.getCurrentInstance().responseComplete();

        return null;
    }
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b style="background-color: #fb5e53; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 18px; line-height: 25px;"&gt;&lt;span style="background-color: #fff2cc; font-size: medium;"&gt;Download the Sample Project from my &amp;nbsp;&lt;a href="https://github.com/ramkicse/ChartImageJasperReport" style="color: #4e40d6; text-decoration: none;" target="_blank"&gt;GitHub&lt;/a&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b style="background-color: #fb5e53; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 18px; line-height: 25px;"&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b style="background-color: #fb5e53; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 18px; line-height: 25px;"&gt;&lt;br /&gt;&lt;/b&gt;
Check the&amp;nbsp;screen-cast&amp;nbsp;for better understanding.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #990000; font-size: large;"&gt;Screen cast:&lt;/span&gt;&lt;/b&gt;&lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="480" src="http://www.youtube.com/embed/DaxMHyJ-haY" width="700"&gt;&lt;/iframe&gt;
&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=uWhgdUxd6lw:XRAuCeII3YU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=uWhgdUxd6lw:XRAuCeII3YU:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=uWhgdUxd6lw:XRAuCeII3YU:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?i=uWhgdUxd6lw:XRAuCeII3YU:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=uWhgdUxd6lw:XRAuCeII3YU:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ramki/feeds/~4/uWhgdUxd6lw" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ramki/feeds/~3/uWhgdUxd6lw/integrate-chart-image-into-jasper.html</link><author>noreply@blogger.com (Rama krishnnan E P)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-blQh4fe8Yzo/UFA91t8YnUI/AAAAAAAAClY/CeigA9_RD1A/s72-c/image_property.png" height="72" width="72" /><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /><feedburner:origLink>http://www.ramkitech.com/2012/09/integrate-chart-image-into-jasper.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-6364888110286960545</guid><pubDate>Wed, 05 Sep 2012 10:01:00 +0000</pubDate><atom:updated>2013-04-12T11:18:47.141+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">charts</category><category domain="http://www.blogger.com/atom/ns#">iReport</category><category domain="http://www.blogger.com/atom/ns#">JSF 2.0</category><category domain="http://www.blogger.com/atom/ns#">JasperReports</category><title>Integrate Charts in Jasper Reports +JSF 2.0</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
In this post we will walk through how to integrate Charts (JFreeChart) into Jasper Report framework.&amp;nbsp;JasperReports is the world's most popular open source reporting engine. It is entirely written in Java and it is able to use data coming from any kind of data source and produce pixel-perfect documents that can be viewed, printed or exported in a variety of document formats including HTML, PDF, Xlsx, Docx, Pptx, Odf&lt;br /&gt;
&lt;br /&gt;
Check my&amp;nbsp;&lt;a href="http://www.ramkitech.com/2011/11/jsf-jpa-jasperreports-ireport.html" target="_blank"&gt;Introduction&amp;nbsp;to Jasper Reports&lt;/a&gt; and&amp;nbsp;&lt;a href="http://www.ramkitech.com/2012/06/jsf-jpa-jasperreports-ireport-part-2.html" target="_blank"&gt;Sub-report&amp;nbsp;with jasper Report &lt;/a&gt;posts.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #990000; font-size: large;"&gt;&lt;b&gt;2-ways to Integrate the Charts/Graphs into Jasper Reports&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style="text-align: left;"&gt;
&lt;/div&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;Use JFreeChart API inside Jasper Report to generate the Charts while generating reports&lt;/li&gt;
&lt;li&gt;Use any 3rd party Java Libraries to create the chart and stored in In-memory Image object (or) stored in file. then pass the Image/file to&amp;nbsp;Jasper Report. then&amp;nbsp;embed&amp;nbsp;the Image into Report. (check &lt;a href="http://www.ramkitech.com/2012/09/integrate-chart-image-into-jasper.html" target="_blank"&gt;here&lt;/a&gt;)&lt;/li&gt;
&lt;/ol&gt;
In this post we going to use 1st option. In Jasper Report use JFreeChart Components to make charts. In my&lt;a href="http://www.ramkitech.com/2012/09/integrate-chart-image-into-jasper.html" target="_blank"&gt; next post &lt;/a&gt;we will see the 2nd way to&amp;nbsp;generate&amp;nbsp;the charts in reports.&lt;br /&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
I ll create one sample application (Progress Report) to&amp;nbsp;demonstrate&amp;nbsp;the&amp;nbsp;Integrate&amp;nbsp;the charts in reports.&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
I have Student Bean contain name, roll No, image and List of Semester paper beans. In&amp;nbsp;Semester paper bean contain name of the paper and mark(score).&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;Student.java&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;import java.util.List;

/**
 *
 * @author ramki
 */
public class Student {
    private String name;
    private String rollNo;
    private String imagePath;
    private List&lt;semesterpaper&gt; listOfSemesterPaper;

    // getters and setters
}
&lt;/semesterpaper&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;SemesterPaper.java&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;public class SemesterPaper {
    
    private String name;
    private double mark;

   
    public SemesterPaper(String name, double mark) {
        this.name = name;
        this.mark = mark;
    }

    // getters and setters
    
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #990000; font-size: large;"&gt;Create the Report&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; we can use either iReport Standalone version or Jasper report&amp;nbsp;Net-beans&amp;nbsp;plugins to create the jasper Reports. &lt;br /&gt;
&lt;br /&gt;
Create empty reports and create the&amp;nbsp;fields&amp;nbsp;and these fields are match with &lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;&lt;span style="color: purple;"&gt;Student&lt;/span&gt;&lt;/b&gt;&lt;/span&gt; bean property&amp;nbsp;variables. here &lt;span style="color: magenta;"&gt;name&lt;/span&gt;,&lt;span style="color: magenta;"&gt;rollNo&lt;/span&gt; and &lt;span style="color: magenta;"&gt;imagePath&lt;/span&gt; are String. so no need to change the data type of field. but &lt;span style="color: magenta;"&gt;listOfSemesterPaper&lt;/span&gt; is List. so change the data type of the field to List.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-ThOSYtC6bfs/UEccX6dJchI/AAAAAAAACkQ/tdCyZKcPERI/s1600/fields_report.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-ThOSYtC6bfs/UEccX6dJchI/AAAAAAAACkQ/tdCyZKcPERI/s1600/fields_report.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
then drag Image component and static text&amp;nbsp;component&amp;nbsp;for making general&amp;nbsp;report&amp;nbsp;like this&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-VIiovgM-LuI/UEcdBbPf3qI/AAAAAAAACkY/5NA0QaojzBc/s1600/report_canvas.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="295" src="http://2.bp.blogspot.com/-VIiovgM-LuI/UEcdBbPf3qI/AAAAAAAACkY/5NA0QaojzBc/s400/report_canvas.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
here &lt;span style="color: magenta;"&gt;name&lt;/span&gt; and &lt;span style="color: magenta;"&gt;rollNo&lt;/span&gt; fields are dragged into report canvas, then drag the Image component and change the expression of Image component to &lt;span style="color: magenta;"&gt;imagePath&lt;/span&gt; field. Now we ready for bring the Chart component. But chart data are&amp;nbsp;stored&amp;nbsp;in &lt;span style="color: magenta;"&gt;listOfSemesterPaper&lt;/span&gt; field. Its List. So we can't use directly. so we going to create sub data set from main data set. so create sub dataset named &lt;b style="background-color: #fff2cc;"&gt;"ChartDataset"&lt;/b&gt;. and In sub data set create another 2 fields match with &lt;span style="background-color: #fff2cc;"&gt;&lt;span style="color: purple;"&gt;&lt;b&gt;SemesterPaper&lt;/b&gt;&lt;/span&gt;&lt;/span&gt; bean. here &lt;span style="color: magenta;"&gt;name&lt;/span&gt; is String and &lt;span style="color: magenta;"&gt;mark&lt;/span&gt; is double.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-LD9bsjpqkog/UEceO-N_T7I/AAAAAAAACkg/x53ZN6rdw9o/s1600/sub_dataset.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="170" src="http://4.bp.blogspot.com/-LD9bsjpqkog/UEceO-N_T7I/AAAAAAAACkg/x53ZN6rdw9o/s200/sub_dataset.png" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now drag the chart and choose the chart type. here i chosen Bar chart. its poped up the wizard. &amp;nbsp;we need to choose Data set. here we need to choose &lt;b style="background-color: #fff2cc;"&gt;"ChartDataset"&lt;/b&gt;&amp;nbsp;sub data set, which one we created. then select the&amp;nbsp;Category&amp;nbsp;and Value&amp;nbsp;property&amp;nbsp;of Charts. here &lt;span style="color: magenta;"&gt;name&lt;/span&gt; is category and &lt;span style="color: magenta;"&gt;mark&lt;/span&gt; is value.&lt;span style="background-color: #fff2cc;"&gt; (see the screenshot)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-xvYpfBoyREk/UEcfgV_78BI/AAAAAAAACko/0xO_mg8_jhg/s1600/chart_wizard.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="321" src="http://3.bp.blogspot.com/-xvYpfBoyREk/UEcfgV_78BI/AAAAAAAACko/0xO_mg8_jhg/s400/chart_wizard.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
and final step is we need to explicitly mention how main data set is divied into sub data set. In sub data set &lt;b style="background-color: #fff2cc;"&gt;"ChartDataset"&lt;/b&gt; is take value of &lt;span style="color: magenta;"&gt;listOfSemesterPaper&lt;/span&gt; field. this fields is List. so we need to wrap into &lt;b&gt;JRBeanCollectionDataSource&lt;/b&gt;.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-5qvdsVuf6Tw/UEcgfzaYi2I/AAAAAAAACkw/am_brwicp9k/s1600/subdataset.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="206" src="http://1.bp.blogspot.com/-5qvdsVuf6Tw/UEcgfzaYi2I/AAAAAAAACkw/am_brwicp9k/s400/subdataset.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
that's&amp;nbsp;it. now compile the report and generate the .jasper format. then integrate into Netbeans project.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;DemoBean.java
&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;@ManagedBean
@SessionScoped
public class DemoBean {

    private List&lt;student&gt; listOfStudent;

    public DemoBean() {
        listOfStudent = new ArrayList&lt;student&gt;();

        Student student = new Student();
        student.setName("Ramki");
        student.setRollNo("02CS24");
        student.setImagePath("C:\\Users\\ramki\\Downloads\\ramki.jpg");

        List&lt;semesterpaper&gt; listOfSemsterPaper = new ArrayList&lt;semesterpaper&gt;();
        listOfSemsterPaper.add(new SemesterPaper("S/W Engg", 50.6));
        listOfSemsterPaper.add(new SemesterPaper("Java", 88.6));
        listOfSemsterPaper.add(new SemesterPaper("Data Struct", 66.6));
        listOfSemsterPaper.add(new SemesterPaper("Algorithm", 77.6));
        listOfSemsterPaper.add(new SemesterPaper("Lab 1", 90.6));
        listOfSemsterPaper.add(new SemesterPaper("Lab 2", 99.6));

        student.setListOfSemsterPaper(listOfSemsterPaper);

        listOfStudent.add(student);


    }

    public String pdf() throws JRException, IOException {
        JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(listOfStudent);
        String reportPath = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/reports/chartReports.jasper");
        JasperPrint jasperPrint = JasperFillManager.fillReport(reportPath, new HashMap(), beanCollectionDataSource);
        HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
        httpServletResponse.addHeader("Content-disposition", "attachment; filename=report.pdf");
        ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream();
        JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream);
        FacesContext.getCurrentInstance().responseComplete();
        return null;
    }
}

&lt;/semesterpaper&gt;&lt;/semesterpaper&gt;&lt;/student&gt;&lt;/student&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;index.xhtml
&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class="html" name="code"&gt;    &lt;h:head&gt;
        &lt;title&gt;Facelet Title&lt;/title&gt;
    &lt;/h:head&gt;
    &lt;h:body&gt;
        &lt;h:form&gt;
            Generating Report : &lt;h:commandbutton action="#{demoBean.pdf()}" value="Generate"&gt;
        &lt;/h:commandbutton&gt;&lt;/h:form&gt;
    &lt;/h:body&gt;

&lt;/pre&gt;
&lt;b&gt;&lt;span style="background-color: #fff2cc; font-size: large;"&gt;Download the Sample Project from my &amp;nbsp;&lt;a href="https://github.com/ramkicse/ChartJasperReport" target="_blank"&gt;GitHub&lt;/a&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Watch in HD&lt;br /&gt;
&lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="480" src="http://www.youtube.com/embed/D2IsIzcuyBo" width="700"&gt;&lt;/iframe&gt;

&lt;br /&gt;
&lt;span style="color: #990000; font-size: large;"&gt;&lt;b&gt;Comments are Welcomed

&lt;/b&gt;&lt;/span&gt;
&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=ZHd7DDl1xpo:qixPguEninA:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=ZHd7DDl1xpo:qixPguEninA:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=ZHd7DDl1xpo:qixPguEninA:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?i=ZHd7DDl1xpo:qixPguEninA:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=ZHd7DDl1xpo:qixPguEninA:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ramki/feeds/~4/ZHd7DDl1xpo" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ramki/feeds/~3/ZHd7DDl1xpo/integrate-charts-in-jasper-reports-jsf.html</link><author>noreply@blogger.com (Rama krishnnan E P)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-ThOSYtC6bfs/UEccX6dJchI/AAAAAAAACkQ/tdCyZKcPERI/s72-c/fields_report.png" height="72" width="72" /><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /><feedburner:origLink>http://www.ramkitech.com/2012/09/integrate-charts-in-jasper-reports-jsf.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-89294498660745824</guid><pubDate>Fri, 22 Jun 2012 06:28:00 +0000</pubDate><atom:updated>2012-07-12T18:27:01.013+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">javaEE</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">Tomcat</category><category domain="http://www.blogger.com/atom/ns#">JasperReports</category><title>Deploy the Java Web Application to Jelastic Paas Cloud</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;a href="http://jelastic.com/" target="_blank"&gt;Jelastic&lt;/a&gt; is Java Paas (Platform as a Service) cloud for Java Server hosting. we can easily create the server&amp;nbsp;&lt;span style="background-color: white;"&gt;instances&lt;/span&gt;&lt;span style="background-color: white;"&gt;(Tomcat, Glassfish ) and SQL Instances (MySQL, PostgreSQL) &amp;nbsp;and deploy the Java Web applications.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a href="http://jelastic.com/" target="_blank"&gt;Jelastic&lt;/a&gt;&amp;nbsp;website make its easy to use. when we logged in &amp;nbsp;one of the server then one window popped up, to create the environment&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-Q4HiwxKoQHA/T-QJ92YZo-I/AAAAAAAACU4/iEaFI1qz_DE/s1600/environment.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="328" src="http://2.bp.blogspot.com/-Q4HiwxKoQHA/T-QJ92YZo-I/AAAAAAAACU4/iEaFI1qz_DE/s640/environment.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style="background-color: white;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
here we select servers (Tomcat, GlassFish), Database Servers (MySQL,PostgreSQL) and give the unique name of ur environment. then&amp;nbsp;click&amp;nbsp;create button. Jelastic create the tomcat and&amp;nbsp;MySQL&amp;nbsp;instances. these&amp;nbsp;instance&amp;nbsp;are not shared to others. so we can start/stop these instance at any time. we can change the config files like Tomcat (server.xml, catalina.properties), MySQL(mysql.ini) files.&lt;br /&gt;
&lt;br /&gt;
When we create the instances they send mail contain the user name and password for accessing the Database server.&lt;br /&gt;
&lt;br /&gt;
In this&amp;nbsp;screen-cast&amp;nbsp;(below) i deploy the &amp;nbsp;previous post&lt;a href="http://www.ramkitech.com/2012/06/jsf-jpa-jasperreports-ireport-part-2.html" target="_blank"&gt; Jasper Report +JSF+JPA &lt;/a&gt;Web Application into&amp;nbsp;Jelastic&amp;nbsp;paas cloud.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #990000; font-size: large;"&gt;&lt;b&gt;Screen Cast&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;iframe allowfullscreen="" frameborder="0" height="480" src="http://www.youtube.com/embed/P7PxUygPlyA" width="853"&gt;&lt;/iframe&gt;
&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=hYQ0OfXz6Uo:C9DXO2Zx9Yg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=hYQ0OfXz6Uo:C9DXO2Zx9Yg:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=hYQ0OfXz6Uo:C9DXO2Zx9Yg:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?i=hYQ0OfXz6Uo:C9DXO2Zx9Yg:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=hYQ0OfXz6Uo:C9DXO2Zx9Yg:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ramki/feeds/~4/hYQ0OfXz6Uo" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ramki/feeds/~3/hYQ0OfXz6Uo/deploy-java-web-application-to-jelastic.html</link><author>noreply@blogger.com (Rama krishnnan E P)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-Q4HiwxKoQHA/T-QJ92YZo-I/AAAAAAAACU4/iEaFI1qz_DE/s72-c/environment.png" height="72" width="72" /><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /><feedburner:origLink>http://www.ramkitech.com/2012/06/deploy-java-web-application-to-jelastic.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-938483298119133822</guid><pubDate>Thu, 21 Jun 2012 10:12:00 +0000</pubDate><atom:updated>2012-09-10T16:51:53.887+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">javaEE</category><category domain="http://www.blogger.com/atom/ns#">Java SE</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">JSF 2.0</category><category domain="http://www.blogger.com/atom/ns#">JasperReports</category><title>JSF + JPA + JasperReports (iReport) Part 2</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
In this post &amp;nbsp;is &amp;nbsp;a&amp;nbsp;continuation&amp;nbsp;of &lt;a href="http://www.ramkitech.com/2011/11/jsf-jpa-jasperreports-ireport.html" target="_blank"&gt;Jasper Report Part 1&lt;/a&gt;. here we will discuss about some advanced jasper report concepts like passing complex object like List, Date object and how to create and use local variable in jasper report, Add the&amp;nbsp;sub-report&amp;nbsp;and background image to report.&amp;nbsp;Check my latest post about&amp;nbsp;&lt;a href="http://www.ramkitech.com/2012/09/integrate-charts-in-jasper-reports-jsf.html" target="_blank"&gt;Integrate Charts into Jasper Reports&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
here i am using JPA (Java Persistence API) for accessing the Database. so i create the two entity ShoppingCart and Item. here ShoppingCart entity contain list of Item entities. then i am going to pass these objects to Jasper Report. &lt;span style="color: blue;"&gt;(Check the video in below)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: blue;"&gt;&lt;b&gt;ShoppingCart.java&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;@Entity
public class ShoppingCart {
    @Id
    @GeneratedValue(strategy= GenerationType.AUTO)
    private long id;
    private String firstName;
    private String lastName;
    @Temporal(TemporalType.DATE)
    private Date dop;
    @OneToMany(cascade= CascadeType.ALL)
    private List&lt;item&gt; listOfItems;

    // getters and setters
}
&lt;/item&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style="color: blue;"&gt;&lt;b&gt;Item.java&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;@Entity
public class Item {
    @Id
    @GeneratedValue(strategy= GenerationType.AUTO)
    private long id;
    private String itemName;
    private float price;
    private int noOfUnits;

    //getters and setters

}
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #990000;"&gt;Create Report&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; now i am going create report. we can use iReport standalone or iReport Netbeans Plugin to create the report. first we need to create some fields in report. these&amp;nbsp;fields&amp;nbsp;are matched with ShoppingCart Bean property names and Data types also.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-EGefpjYQBUo/T-LnUWUKB8I/AAAAAAAACT4/hlQ2Dl1b7oA/s1600/fields.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-EGefpjYQBUo/T-LnUWUKB8I/AAAAAAAACT4/hlQ2Dl1b7oA/s1600/fields.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
and set the data types of these fields correctly.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="background-color: #fce5cd;"&gt;firstName &amp;nbsp;==&amp;gt; java.lang.String&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style="background-color: #fce5cd;"&gt;lastName &amp;nbsp;==&amp;gt; java.lang.String&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: #fce5cd;"&gt;dop &amp;nbsp;==&amp;gt; java.util.Date&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: #fce5cd;"&gt;listOfItems ==&amp;gt; java.util.List&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
then drag these fields to detail pane of the report as per needs. then right click the Report and compile the report&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-8VtsYuGAz4c/T-Lo1tPqVKI/AAAAAAAACUM/avfXVqU4Zv8/s1600/compile.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="260" src="http://4.bp.blogspot.com/-8VtsYuGAz4c/T-Lo1tPqVKI/AAAAAAAACUM/avfXVqU4Zv8/s320/compile.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
then its creates the jasper file. and its compiled format of jasper report. check&lt;a href="http://www.ramkitech.com/2011/11/jsf-jpa-jasperreports-ireport.html" target="_blank"&gt; part 1&lt;/a&gt; for more details of overview of jasper report.&lt;br /&gt;
&lt;br /&gt;
now create one JSF page with single Command Button (Submit Button&lt;span style="background-color: white;"&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;pre class="xml" name="code"&gt;    &lt;h:head&gt;
        &lt;title&gt;Facelet Title&lt;/title&gt;
    &lt;/h:head&gt;
    &lt;h:body&gt;
        &lt;h:form&gt;
            &lt;h:commandbutton action="#{demoBean.pdf()}" value="Generate Jasper Report"&gt;
        &lt;/h:commandbutton&gt;&lt;/h:form&gt;
    &lt;/h:body&gt;

&lt;/pre&gt;
&lt;span style="background-color: white;"&gt;and we create one managed bean for above JSF page&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;DemoBean.java&lt;/span&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;@ManagedBean
@SessionScoped

public class DemoBean {
    
     public void pdf() throws JRException, IOException {
     
         EntityManager em=PerisitenceManager.getEntityManager();
        Query query= em.createQuery("select s from ShoppingCart s");
         List&lt;shoppingcart&gt; listOfShoppingCart=(List&lt;shoppingcart&gt;)query.getResultList();
        JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(listOfShoppingCart);
        String reportPath = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/reports/report.jasper");
        JasperPrint jasperPrint = JasperFillManager.fillReport(reportPath, new HashMap(), beanCollectionDataSource);
        HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
        httpServletResponse.addHeader("Content-disposition", "attachment; filename=report.pdf");
        ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream();
        JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream);
        FacesContext.getCurrentInstance().responseComplete();
    }
}
&lt;/shoppingcart&gt;&lt;/shoppingcart&gt;&lt;/pre&gt;
&lt;br /&gt;
Now when u run the project its generate the report in PDF file format.&lt;br /&gt;
&lt;br /&gt;
now we integrate the sub report. so drag the&amp;nbsp;sub-report&amp;nbsp;component from&amp;nbsp;palettes. then add the Item beans property as a fields names and correct data types.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-A8AepawzTdI/T-LwUB8FoFI/AAAAAAAACUY/amkJW4FSFls/s1600/sub.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-A8AepawzTdI/T-LwUB8FoFI/AAAAAAAACUY/amkJW4FSFls/s1600/sub.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
and data types&lt;br /&gt;
&lt;span style="background-color: #fce5cd;"&gt;itemName ==&amp;gt; java.lang.String&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fce5cd;"&gt;price ==&amp;gt; java.lang.Float&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fce5cd;"&gt;noOfUnits ==&amp;gt; &amp;nbsp;java.lang.Integer&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
once sub report is ready then compile the subreports.&lt;br /&gt;
&lt;br /&gt;
while create the subreport we passed the Empty Data Source. so now we need to change to listOfItems as a data source, we can't pass directly because its not accept List. so we need to wrap into the JRBeanCollectionDataSource Object.&lt;br /&gt;
&lt;br /&gt;
so in main report select the sub report and change the properties&lt;br /&gt;
&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;Connection Type ==&amp;gt; Use a datasource Expression&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;DataSource Expression ==&amp;gt; new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{listOfItems})&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-56uGSalJpNg/T-LxyDj5QDI/AAAAAAAACUg/B4AWQnVcoXA/s1600/datasource.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="268" src="http://1.bp.blogspot.com/-56uGSalJpNg/T-LxyDj5QDI/AAAAAAAACUg/B4AWQnVcoXA/s320/datasource.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #990000;"&gt;&lt;b&gt;You Can Download this complete example from &lt;a href="https://github.com/ramkicse/JasperReports-2.git" target="_blank"&gt;GitHub&lt;/a&gt; (or) &lt;a href="http://ramki-projects.googlecode.com/files/JasperDemo.zip" target="_blank"&gt;google code&lt;/a&gt; .&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #990000;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style="color: red; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"&gt;&lt;span style="line-height: 25px;"&gt;&lt;u&gt;&lt;b&gt;How to use&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;&lt;span style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"&gt;&lt;span style="line-height: 25px;"&gt;Change the properties in &lt;span style="background-color: #fff2cc;"&gt;persistence.xml&lt;/span&gt; file, like db name, db hostname ,username and password.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"&gt;&lt;span style="line-height: 25px;"&gt;Add necessary lib to&amp;nbsp;class path&amp;nbsp;like Hibernate libs, MySQL lib, Jasper Report lib. for simplicity in this zip&amp;nbsp;contain&amp;nbsp;war file under dist/ folder. so just extract &amp;nbsp; and see all lib are located in &lt;span style="background-color: #fff2cc;"&gt;WEB-INF/lib&lt;/span&gt; section. copy all files and add to to ur&amp;nbsp;class path&amp;nbsp;(Libraries&amp;nbsp;)&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"&gt;&lt;span style="line-height: 25px;"&gt;Create the &lt;b style="background-color: #fff2cc;"&gt;jasperdb&lt;/b&gt; database in ur mysql server&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"&gt;&lt;span style="line-height: 25px;"&gt;First run the &lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;NewServlet&lt;/b&gt;&lt;/span&gt; , this servlet create necessary tables in ur database. and insert some sample rows to the table.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;"&gt;&lt;span style="line-height: 25px;"&gt;Finally run the&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt; index.xhtml&lt;/b&gt;&lt;/span&gt; file and generate the report.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;br /&gt;&lt;/span&gt;
&lt;strike&gt;&lt;span style="background-color: #fff2cc;"&gt;I deployed same example in &lt;b&gt;&lt;span style="color: #990000;"&gt;Jelastic Paas cloud,&amp;nbsp;&lt;/span&gt;&lt;/b&gt;you can access through&amp;nbsp;&lt;/span&gt;&lt;b&gt;&lt;a href="http://ramkicse.jelastic.servint.net/jasper/" style="background-color: #fce5cd;"&gt;http://ramkicse.jelastic.servint.net/jasper/&lt;/a&gt;&lt;span style="background-color: #fff2cc;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span style="background-color: #fff2cc;"&gt;URL&lt;/span&gt;&lt;/strike&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;strike&gt;click the button to generate the report.&amp;nbsp;&lt;/strike&gt;(Its expired)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
check &lt;a href="http://www.ramkitech.com/2012/06/deploy-java-web-application-to-jelastic.html" target="_blank"&gt;How to deploy the Web application to Jelastic cloud&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Check my latest post about &lt;a href="http://www.ramkitech.com/2012/09/integrate-charts-in-jasper-reports-jsf.html" target="_blank"&gt;Integrate Charts into Jasper Reports&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span id="video" style="font-size: large;"&gt;&lt;b style="color: #990000;"&gt;Screen Cast &lt;/b&gt;&lt;span style="background-color: #fff2cc; color: #990000;"&gt;(Watch the video in HD)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;iframe allowfullscreen="" frameborder="0" height="480" src="http://www.youtube.com/embed/dgLjnnnvDmk" width="853"&gt;&lt;/iframe&gt;

&lt;br /&gt;
&lt;span style="color: #990000; font-size: large;"&gt;&lt;b&gt;Comments are Welcomed

&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=ULzSlTDr7DQ:wDKFBf6r8wU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=ULzSlTDr7DQ:wDKFBf6r8wU:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=ULzSlTDr7DQ:wDKFBf6r8wU:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?i=ULzSlTDr7DQ:wDKFBf6r8wU:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=ULzSlTDr7DQ:wDKFBf6r8wU:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ramki/feeds/~4/ULzSlTDr7DQ" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ramki/feeds/~3/ULzSlTDr7DQ/jsf-jpa-jasperreports-ireport-part-2.html</link><author>noreply@blogger.com (Rama krishnnan E P)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-EGefpjYQBUo/T-LnUWUKB8I/AAAAAAAACT4/hlQ2Dl1b7oA/s72-c/fields.png" height="72" width="72" /><georss:featurename>National Highway 4, Kasba Peth, Pune, Maharashtra, India</georss:featurename><georss:point>18.5204303 73.8567437</georss:point><georss:box>18.3999798 73.6988152 18.6408808 74.01467219999999</georss:box><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /><feedburner:origLink>http://www.ramkitech.com/2012/06/jsf-jpa-jasperreports-ireport-part-2.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-6996415716517830633</guid><pubDate>Sat, 28 Apr 2012 10:43:00 +0000</pubDate><atom:updated>2012-07-01T11:49:34.063+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Linux</category><category domain="http://www.blogger.com/atom/ns#">SSH</category><category domain="http://www.blogger.com/atom/ns#">SSH Tunneling</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><title>How to do SSH Tunneling (Port Forwarding) - Screen-cast</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
In this post we will see how ssh works?,&amp;nbsp;what is SSH tunneling? what is important of ssh tunnels and how to setup the ssh tunnel.&lt;br /&gt;
When SSH server is installed in machine then by default its allowed ssh tunneling.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #660000; font-size: large;"&gt;&lt;b&gt;SSH Tunneling (Port Forwarding)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
Tunneling&amp;nbsp;is the concept to encapsulate the network protocol to another protocol. here we put into SSH. so all network communication are encrypted. It also called Port&amp;nbsp;Forwarding. because in ssh tunneling we are&amp;nbsp;going&amp;nbsp;to bind one local port. so what are the packet we are going to send that particular port, all&amp;nbsp;packets&amp;nbsp;are transparently encrypt and delivered to remote system.&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #660000; font-size: large;"&gt;&lt;b&gt;What is the need for SSH Tunneling?&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;SSH is enough to administrate the remote system. its not enough to access the all services which are&amp;nbsp;available&amp;nbsp;in remote system.&lt;/div&gt;
&lt;div&gt;
let i describe in the following scenario,&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-UwBBYy88FXM/T5ZGv9ack5I/AAAAAAAACMc/kjEY-69KYY8/s1600/scenario.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="312" src="http://2.bp.blogspot.com/-UwBBYy88FXM/T5ZGv9ack5I/AAAAAAAACMc/kjEY-69KYY8/s640/scenario.jpg" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
now lets consider the scenario, System (192.168.56.101) is my system its connected to internet and server its called PrivateServer (192.168.56.102) &amp;nbsp;machine have two&amp;nbsp;Ethernet&amp;nbsp;interfaces. one is connected to Internet. and another is connected to 10.10.1.0/24 local network. Intranet (10.10.1.11) machine is part of&amp;nbsp;10.10.1.0/24&amp;nbsp; sub network.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Note : here i mentioned local system(192.168.56.101) and remote system(192.168.56.102) are looking like local&amp;nbsp;sub-net&amp;nbsp;IP address. For VM&amp;nbsp;purpose&amp;nbsp;i used these IP address. But reality is it&amp;nbsp;should&amp;nbsp;be any public IP address.&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Important Note : SSH Server&amp;nbsp;daemon&amp;nbsp;service is running in port 22 in all these three system and firewall is allowed to connect these system using SSH client.&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
now&amp;nbsp;System (192.168.56.101) can&amp;nbsp;communicate&amp;nbsp;to&amp;nbsp;PrivateServer (192.168.56.102), because both system are connected to internet directly. But&amp;nbsp;System (192.168.56.101) can't communicate to Intranet (10.10.1.11) machine, because from&amp;nbsp;System (192.168.56.101) perspective 10.10.1.11 is non&amp;nbsp;route able&amp;nbsp;IP address. 10.10.1.11 is not public IP address, its local IP address. so we can't route the packets directly.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Now the situation like that from System(192.168.56.101)&lt;span style="background-color: #fff2cc;"&gt; i want to access the Intranet (10.10.1.11) machine. &lt;b&gt;without&amp;nbsp;modifying&amp;nbsp;IP tables, redirect, like tools/services in intermediate (or) target machine. Because i m not sys-admin, so i&amp;nbsp;don't&amp;nbsp;have root&amp;nbsp;privilege.&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
One of the possible&amp;nbsp;solution is first use ssh to&amp;nbsp;log in&amp;nbsp;into PrivateServer(192.168.56.102) and then again&amp;nbsp;(nested)&amp;nbsp;log in&amp;nbsp;&amp;nbsp;to Intranet(10.10.1.11). Yes its good idea, its works, now i can remotely&amp;nbsp;administrate&amp;nbsp;the Intranet(10.10.1.11). but if Intranet(10.10.1.11) offer some services like VNC, Apache httpd, smtp, pop3, squid proxy then&lt;b&gt; how we can access these services from System(192.168.56.101)?&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
here its not strictly Intranet(10.10.1.11) offer these service, it may be 10.10.1.0/24 sub net any one of the machine can offer these services. Even in 10.10.1.0/24&amp;nbsp;sub-net&amp;nbsp;have one intranet-website. how we can access&amp;nbsp;these&amp;nbsp;site from System(192.168.56.101) machine&amp;nbsp;Firefox?&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;The&amp;nbsp;solution&amp;nbsp;is SSH Tunneling or SSH Port Forwarding&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style="color: #660000; font-size: large;"&gt;How SSH Works&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/b&gt; &amp;nbsp; &amp;nbsp; In terminal when we type &lt;b style="background-color: #d9ead3;"&gt;ssh ramki@Private-Server.org&lt;/b&gt;&amp;nbsp; then terminal application invoke the ssh client, ssh client connect to&amp;nbsp;Private-Server.org's&amp;nbsp;SSH server in port 22. then both client and server exchange the&amp;nbsp;identity,&amp;nbsp;&amp;nbsp;public keys, cipher suite&amp;nbsp;information and create one shell process in server side. then secure channel is established between client and server. then future all commands from 192.168.101 are go through this secure channel to server (192.168.56.102) and execute the command&amp;nbsp;and the response are come back in same secure channel.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
For example after establish ssh, i will issue the ls command. the ls command goes to SSH client then that command encapsulate and&amp;nbsp;encrypted&amp;nbsp;then send to server. Server decrypt and extract the command and&amp;nbsp;execute&amp;nbsp;the command in shell (which is created when ssh is established), the&amp;nbsp;output&amp;nbsp;of ls command is not printed in shell. Its redirect the output to SSH client in same secure channel and follow the same procedure (encapsulate and&amp;nbsp;encrypt) . and finally Terminal application shows the&amp;nbsp;output&amp;nbsp;of ls command.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
I think here all command is encoded to Base64 encoding before send to server and before encrypt.&lt;b&gt; &lt;span style="background-color: #fce5cd;"&gt;(But i am not sure)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
here very important note that SSH is not&amp;nbsp;disturb&amp;nbsp; the port&amp;nbsp;other than&amp;nbsp;22 (or which port ssh server is running).&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-oIq-qgce-q8/T5ZGxFEmHiI/AAAAAAAACMg/8l8pL_wCIh4/s1600/ssh_works.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="419" src="http://3.bp.blogspot.com/-oIq-qgce-q8/T5ZGxFEmHiI/AAAAAAAACMg/8l8pL_wCIh4/s640/ssh_works.jpg" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style="color: #660000; font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style="color: #660000; font-size: large;"&gt;SSH Tunneling&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&amp;nbsp;&lt;/b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;SSH can work many channel's simultaneously. In normal case we use shell channel. But now we are going to use data channel. so base concept is, in 192.168.56.101 machine ssh client bind one port and establish secure connection with server (192.168.56.102). and create one data&amp;nbsp;channel&amp;nbsp;and shell channel. (we can&amp;nbsp;omit&amp;nbsp;shell channel&amp;nbsp;using&amp;nbsp;-N option in ssh command).&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Now In system machine (&amp;nbsp;192.168.56.101) any application send data to that port (which one ssh client is bind), then ssh client transparently receive the data and encrypt and sent to server machine. In server&amp;nbsp;&amp;nbsp;(&amp;nbsp;192.168.56.102)&amp;nbsp;receive&amp;nbsp;and decrypt it and make the local call. (we discuss later)&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #660000; font-size: large;"&gt;&lt;b&gt;SSH Tunneling types&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
SSH offers three types of tunneling&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;Dynamic Tunneling (SOCKS Proxy)&lt;/li&gt;
&lt;li&gt;Local Port Forwarding&lt;/li&gt;
&lt;li&gt;Remote Port Forwarding&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style="color: #cc0000; font-family: Verdana, sans-serif;"&gt;&lt;u&gt;Dynamic Tunneling&amp;nbsp;&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #cc0000;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&lt;b&gt;Command : &lt;/b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style="background-color: #fff2cc;"&gt; &lt;b&gt;&lt;span style="color: purple;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #20124d;"&gt;ssh &amp;nbsp; &amp;nbsp; -D 8080 &amp;nbsp; &amp;nbsp; ramki@192.168.56.102&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
here -D 8080 is mention SOCKS v5 Proxy bind 8080 port in client side&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Now ssh client in 192.168.56.101 machine create one SOCKS proxy server in client side&amp;nbsp;and bind one local port.then connect to 192.168.56.102 remote machine and establish secure channel.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&amp;nbsp;Now all client application like Firefox, chrome,... need to configure the proxy setting &amp;nbsp;to SOCKS proxy server localhost and port number. (check video for reference below the post)&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Note : consider server (192.168.56.102) and Intranet (10.10.1.11) both machines run&amp;nbsp;Apache&amp;nbsp;httpd server and bind port 80&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
After configuration is&amp;nbsp;completes,&lt;br /&gt;
in Firefox now type http://localhost/ , we know that in client machine (192.168.56.101) there is no service is running in port 80. but when we hit enter in browser, we can see the website of server machine (192.168.56.102).&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;How we can access server website using http://localhost/ in client machine?&lt;/b&gt;&lt;br /&gt;
we configure the proxy in browser. so browser send all HTTP request (even localhost anf 127.0.0.1) to port 8080, here SOCKS proxy is running in that port. Then socks proxy server packs our HTTP request to ssh client and encrypt and send to server. Server decrypt and&amp;nbsp;extract&amp;nbsp;the HTTP Request. Now in server side the HTTP request&lt;b&gt; http://localhost/&lt;/b&gt; is point to server machine itself. so server invoke the request. If any service is running in port 80, is called and response is send back to client using same secure channel. so browser shows server webpage in client side.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-uYmBjinJPTI/T5ZGqS3XB0I/AAAAAAAACL0/kEvBBWdw3Wc/s1600/dynamic.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="400" src="http://3.bp.blogspot.com/-uYmBjinJPTI/T5ZGqS3XB0I/AAAAAAAACL0/kEvBBWdw3Wc/s640/dynamic.jpg" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
We know that from client machine (192.168.56.101) , the IP address 10.10.1.11 is non routable. but now if we issue&lt;b&gt;&amp;nbsp;http://10.10.1.11/&lt;/b&gt;&amp;nbsp;in&amp;nbsp;Firefox&amp;nbsp;browser, its shows the 10.10.1.11&amp;nbsp;Apache&amp;nbsp;server webpage.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Advantage :&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;One proxy server is enough to access the all services of remote machine and its sub-net services&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Disadvantage:&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;We need to configure the Proxy settings in client application, If&amp;nbsp;application&amp;nbsp;doesn't support the proxy then we can't access the service.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style="color: #cc0000; font-family: Verdana, sans-serif;"&gt;&lt;u&gt;Local Port Forwarding&lt;/u&gt;&lt;/span&gt;&lt;span style="color: red; font-family: Verdana, sans-serif;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Command : &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style="background-color: #fff2cc;"&gt; &amp;nbsp;ssh &amp;nbsp; &amp;nbsp; &amp;nbsp; -L &amp;nbsp;8000:localhost:80 &amp;nbsp; &amp;nbsp; ramki@192.168.56.102&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;here syntax is &amp;nbsp; -L &amp;nbsp; &amp;lt;local port&amp;gt; : &amp;lt;remote hostname&amp;gt; : &amp;lt;remote service port&amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
so when we&amp;nbsp;execute&amp;nbsp;the command, its bind port 8000 in client side. now what are request send to port 6000 its redirect to ssh client, then encrypt and send to server machine. now server directly delivered the data to port 80.&lt;br /&gt;
&lt;br /&gt;
In dynamic tunnel, server checks the packet and decide where we need to send the packet, for example http://localhost/ then its send to 80, smtp then send to 25. But in local port it always send to single port which one we mention during setup the local port forwarding&amp;nbsp;&lt;b&gt;&amp;lt;remote hostname&amp;gt; : &amp;lt;remote service port&amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
this time in Firefox no need to configure the proxy,&amp;nbsp;clear&amp;nbsp;the proxy(if its present)&lt;br /&gt;
and type in address bar &lt;b&gt;&amp;nbsp;http://localhost:8000/&lt;/b&gt;&lt;br /&gt;
then HTTP request is going to local port 8000, then its redirect and send to server. server directly send to port 80. (Its based on&lt;span style="background-color: #fff2cc;"&gt;&amp;nbsp;&lt;/span&gt;&lt;b&gt;&lt;span style="background-color: #fff2cc;"&gt;&amp;lt;remote hostname&amp;gt; : &amp;lt;remote service port&amp;gt;&lt;/span&gt;, here now &lt;span style="background-color: #fff2cc;"&gt;localhost:80&lt;/span&gt;&lt;/b&gt;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-nmmsmmfAetA/T5ZGrYJDRZI/AAAAAAAACL4/skeG6CJMhmg/s1600/local1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="436" src="http://2.bp.blogspot.com/-nmmsmmfAetA/T5ZGrYJDRZI/AAAAAAAACL4/skeG6CJMhmg/s640/local1.jpg" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
If u want to access the 10.10.1.11 machine http service then we need to setup new local port forwarding.&lt;/div&gt;
&lt;div&gt;
we can't use prior port forwarding. because old one always pointing to localhost:80.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Command : &amp;nbsp; &amp;nbsp;&lt;/b&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;b style="background-color: #fff2cc;"&gt; ssh &amp;nbsp; -L &amp;nbsp;8000:10.10.1.11:80 &amp;nbsp; ramki@192.168.56.102&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
now client side local port 8000 is redirected to 10.10.1.11:80 machine via 192.168.56.102.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
In&amp;nbsp;Firefox&amp;nbsp;using http://localhost:8080/ we can access the 10.10.1.11 machine http service.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
(For further reference check the video below. in video i show the how to access remote desktop using VNC)&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-qStTZlKH6Ig/T5ZGsQgDHUI/AAAAAAAACME/mtBGx0eghEk/s1600/local2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="372" src="http://1.bp.blogspot.com/-qStTZlKH6Ig/T5ZGsQgDHUI/AAAAAAAACME/mtBGx0eghEk/s640/local2.jpg" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Advantage:&lt;/b&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;no need to configure the proxy setting&lt;/li&gt;
&lt;/ul&gt;
&lt;b&gt;Disadvantage:&lt;/b&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;Each service we need to setup different local port forwarding, (i.e for example, 2 port forwarding is needed to get 192.168.56.102 and 10.10.1.11 http services)&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #cc0000; font-family: Verdana, sans-serif;"&gt;&lt;u&gt;Remote Port&amp;nbsp;Forwarding&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
Remote port forwarding is same like local port&amp;nbsp;forwarding. but this time we need to set the port forwarding in server side(192.168.56.102), not client side&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Command : &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style="background-color: #fff2cc;"&gt;ssh &amp;nbsp; &amp;nbsp;-R 8000:localhost:80 &amp;nbsp; &amp;nbsp; &amp;nbsp; ramki@192.168.56.101&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
here very important changes is from server we going to connect client, so&amp;nbsp;&lt;span style="background-color: #fff2cc; font-weight: bold;"&gt;&amp;nbsp;ramki@192.168.56.101&lt;/span&gt;&lt;span style="background-color: white;"&gt;&amp;nbsp;here its 192.168.56.101 not 102.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;when we&amp;nbsp;execute&amp;nbsp;this command its connect to client and create 8000 port in &lt;b&gt;client side(not server side)&lt;/b&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;as usual client use its local port 8000 to connect server. like local port forwarding.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;&lt;b&gt;&lt;span style="color: #990000;"&gt;Why Remote Port Forwarding is Important?&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;&amp;nbsp; &amp;nbsp; Its&amp;nbsp;rarely&amp;nbsp;used, when we worked the machine. that machine is inside the NAT. so from outside no one can access it. that kind of situation&amp;nbsp;physically&amp;nbsp;access the machine and connect back to our client system (192.168.56.101) using remote port forward. then from client machine we can access the services.(Its seems to be little bit confusing, but its simple)&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;In Windows Machine&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp;&lt;/b&gt;In windows machine if want to run ssh server then there is lots of ssh servers are&amp;nbsp;available&amp;nbsp;&lt;a href="http://www.bitvise.com/winsshd" target="_blank"&gt;WinSSHD&amp;nbsp;&lt;/a&gt;&lt;a href="http://www.freesshd.com/" target="_blank"&gt;freeSSHd&lt;/a&gt;, &lt;a href="http://sshwindows.sourceforge.net/" target="_blank"&gt;openssh&lt;/a&gt;. If we want only ssh client then we can use &lt;a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html" target="_blank"&gt;Putty&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
suppose in System(192.168.56.101) i am using Windows then how we access the ssh tunneling.&lt;br /&gt;
&lt;br /&gt;
open the putty and type the host ramki@192.168.56.102 and select Connection-&amp;gt;SSH-&amp;gt;Tunnels (see the image), then type &lt;b&gt;8080&lt;/b&gt; in source port and select &lt;b&gt;Dynamic&lt;/b&gt;, if u want dynamic tunnel (Its equal to -D 8080 in command option)&lt;br /&gt;
&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-tue6bke7NeY/T5ZGt-pppfI/AAAAAAAACMM/JKaniuviBzM/s1600/putty.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="387" src="http://1.bp.blogspot.com/-tue6bke7NeY/T5ZGt-pppfI/AAAAAAAACMM/JKaniuviBzM/s400/putty.jpg" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
If we want local port forwarding then put any unused port &lt;b&gt;6000&lt;/b&gt; in source port and destination is &lt;b&gt;localhost:80 &lt;/b&gt;and select &lt;b&gt;Local. &lt;/b&gt;(Its equal to -L 6000:localhost:80)&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-cGNjRr5-5Ug/T5ZGu7mr3wI/AAAAAAAACMQ/YSP7jVJz_n8/s1600/putty1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="388" src="http://4.bp.blogspot.com/-cGNjRr5-5Ug/T5ZGu7mr3wI/AAAAAAAACMQ/YSP7jVJz_n8/s400/putty1.jpg" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
If u want to access 10.10.1.11 machine &amp;nbsp;the remote desktop then make local port&amp;nbsp;forward&amp;nbsp;(check above image) and&amp;nbsp;Destination&amp;nbsp;is &lt;b&gt;10.10.1.11:5900 &lt;/b&gt;here 5900 is the port used by vnc server. then using any vnc client (here i used tightvnc client) to connect ur local port 6000&lt;/div&gt;
&lt;div&gt;
so mention&lt;b&gt; localhost::6000, &amp;nbsp;&lt;/b&gt;&amp;nbsp;here we need to mention double colon &lt;b&gt;::&lt;/b&gt;, because in vnc client port no is specified in this manner. (Check the video )&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-sfLCbg2FbwA/T5ZGyO0vq5I/AAAAAAAACMo/NU4WolfupQU/s1600/vnc.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="168" src="http://4.bp.blogspot.com/-sfLCbg2FbwA/T5ZGyO0vq5I/AAAAAAAACMo/NU4WolfupQU/s400/vnc.jpg" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b style="background-color: #fff2cc;"&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="background-color: white; color: #660000; font-size: large;"&gt;Bypass Firewall&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;This SSH Tunnel&amp;nbsp;concept&amp;nbsp;can be use to bypass firewall. lets&amp;nbsp;consider&amp;nbsp;the scenario. In server side its enable firewall and some service are running and these services are can access through localhost or same machine. but u can't access through remote&amp;nbsp;machine. because firewall block the all the port except ssh port (22).&lt;br /&gt;
&lt;br /&gt;
this kind of situation we use tunnel and almost all services can be accessed from outside. because firewall is rule based. In firewall perspective all traffic is goes through port 22. so its allowed. but internally we made tunnel and access all services.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #660000; font-size: large;"&gt;How to prevent SSH Tunnel&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; Open the ssh server config file&lt;b&gt; /etc/ssh/sshd_config &lt;/b&gt;&amp;nbsp;then set the parameter&lt;br /&gt;
&lt;b style="background-color: #fce5cd;"&gt;AllowTcpForwarding no&lt;/b&gt;&lt;br /&gt;
then restart ssh service. then they not allow the ssh tunnel service, but still we can access ssh shell service.&lt;br /&gt;
&lt;br /&gt;
But in ssh man page they&amp;nbsp;clearly&amp;nbsp;mentioned&lt;br /&gt;
&lt;br /&gt;
&lt;b style="background-color: #fff2cc;"&gt;" Note that disabling TCP forwarding does not improve security unless&amp;nbsp;users are also denied shell access, as they can always install their own forwarders. "&lt;/b&gt;&lt;br /&gt;
&lt;div&gt;
so still we can use use ssh tunnel even though &amp;nbsp;we set&amp;nbsp;&lt;b&gt;AllowTcpForwarding no.&lt;/b&gt; (I will show in my next post)&lt;br /&gt;
&lt;br /&gt;
&lt;b style="background-color: #fff2cc;"&gt;I hope everything is clear. If any&amp;nbsp;misunderstanding&amp;nbsp;please&amp;nbsp;let me know.&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style="color: #660000; font-size: large;"&gt;Screen cast (Watch in HD)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;iframe allowfullscreen="" frameborder="0" height="480" src="http://www.youtube.com/embed/VdkLejEN3So?rel=0" width="853"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #660000; font-size: large;"&gt;&lt;b&gt;Resources:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;&lt;a class="l" href="http://www.snailbook.com/" style="background-color: white; color: #1122cc; cursor: pointer; font-family: arial, sans-serif; text-align: -webkit-auto; white-space: nowrap;"&gt;&lt;em style="font-style: normal; font-weight: bold;"&gt;SSH&lt;/em&gt;, The Secure Shell: The Definitive Guide&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;Comments Welcomed&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=fG3uxddkq4g:1EXr4KLIqLs:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=fG3uxddkq4g:1EXr4KLIqLs:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=fG3uxddkq4g:1EXr4KLIqLs:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?i=fG3uxddkq4g:1EXr4KLIqLs:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=fG3uxddkq4g:1EXr4KLIqLs:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ramki/feeds/~4/fG3uxddkq4g" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ramki/feeds/~3/fG3uxddkq4g/how-to-do-ssh-tunneling-port-forwarding.html</link><author>noreply@blogger.com (Rama krishnnan E P)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-UwBBYy88FXM/T5ZGv9ack5I/AAAAAAAACMc/kjEY-69KYY8/s72-c/scenario.jpg" height="72" width="72" /><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /><feedburner:origLink>http://www.ramkitech.com/2012/04/how-to-do-ssh-tunneling-port-forwarding.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-5380334423162876171</guid><pubDate>Tue, 24 Apr 2012 05:49:00 +0000</pubDate><atom:updated>2012-08-22T10:27:08.376+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Linux</category><category domain="http://www.blogger.com/atom/ns#">Kernel</category><title>How to compile kernel step by step</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
Recently I compiled the latest kernel by&amp;nbsp;manually for just fun. so i&amp;nbsp;logged&amp;nbsp;my experience here. I show the step by step to the compilation process. I&amp;nbsp;followed&amp;nbsp;the &lt;a href="http://www.howtoforge.com/kernel_compilation_ubuntu" target="_blank"&gt;this reference&lt;/a&gt; for compile the kernel.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #990000; font-size: large;"&gt;&lt;b&gt;Why Need to compile the Kernel?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Some time some software or modules expected that some&amp;nbsp;kernel&amp;nbsp;flags needed to set while compile (build) the kernel. This kind of scenario we need to rebuild the kernel with specified configuration flags are set.&lt;/li&gt;
&lt;li&gt;When new kernel is&amp;nbsp;released, &amp;nbsp;compile the new kernel and install in our system. But this is not&amp;nbsp;recommend&amp;nbsp;way to install the system. so use our distribution(Ubuntu,&amp;nbsp;red-hat&amp;nbsp;release ) &amp;nbsp;kernel update.&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;span style="color: #cc0000;"&gt;&lt;b&gt;Check your&amp;nbsp;Linux&amp;nbsp;kernel version&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; In Linux&amp;nbsp;system use &lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;uname -r&lt;/b&gt;&lt;/span&gt; or &lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;cat /proc/version&lt;/b&gt;&lt;/span&gt; to find the current kernel version&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-VwizV9ywLPA/T5FL5ibXkmI/AAAAAAAACK0/JJtMFWHudUg/s1600/uname.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="102" src="http://4.bp.blogspot.com/-VwizV9ywLPA/T5FL5ibXkmI/AAAAAAAACK0/JJtMFWHudUg/s400/uname.png" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Linux Kernel Version&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
here &lt;b&gt;2.6.35.22&amp;nbsp;&lt;/b&gt;is current system kernel version&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #990000;"&gt;&lt;b&gt;Step 1 : Download the latest kernel&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;Goto&amp;nbsp;&lt;a href="http://kernel.org/"&gt;http://kernel.org/&lt;/a&gt;&amp;nbsp;website and get the latest version of the kernel source. i will get &lt;b&gt;3.3.3&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b style="background-color: #fff2cc;"&gt;wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.3.3.tar.bz2&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
and extract&amp;nbsp;the source code.&lt;br /&gt;
&lt;b style="background-color: #fff2cc;"&gt;tar xf linux-3.3.3.tar.bz2&lt;/b&gt;&lt;br /&gt;
&lt;b style="background-color: #fff2cc;"&gt;cd linux-3.3.3&lt;/b&gt;&lt;br /&gt;
in linux-3.3.3 folder&amp;nbsp;contain&amp;nbsp;lots of files and folders. some folders are use following purpose&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: red;"&gt;arch&lt;/span&gt;&lt;/b&gt; - this folder shows the what are the&amp;nbsp;architecture&amp;nbsp;port the&amp;nbsp;Linux&lt;br /&gt;
&lt;span style="color: red;"&gt;&lt;b&gt;crypto&lt;/b&gt;&lt;/span&gt;- contain&amp;nbsp;cartographic&amp;nbsp;implementations like AES, DES&lt;br /&gt;
&lt;b&gt;&lt;span style="color: red;"&gt;drivers&lt;/span&gt;&lt;/b&gt;- &amp;nbsp;all device drivers modules (IDE, SCSI, Ethernet device, Wireless)&lt;br /&gt;
&lt;b&gt;&lt;span style="color: red;"&gt;fs&lt;/span&gt;&lt;/b&gt;- all&amp;nbsp;file-system&amp;nbsp;implementation code (ext4, FAT, NTFS)&lt;br /&gt;
&lt;b&gt;&lt;span style="color: red;"&gt;net&lt;/span&gt;&lt;/b&gt; - all network protocol implementations (IPv4, IPv6, tcp, 802.11)&lt;br /&gt;
&lt;br /&gt;
&lt;b style="background-color: #fff2cc;"&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b style="color: #990000;"&gt;Step 2 : make the configuration file&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; While compile the kernel source code, we need configuration file. that configuration file contain lots of variable to help to understand&amp;nbsp;what&amp;nbsp;are the modules we need to compile.&lt;br /&gt;
&lt;br /&gt;
For x86 specific&amp;nbsp;kernel&amp;nbsp;variable check &lt;a href="http://kernel.org/doc/menuconfig/x86.html" target="_blank"&gt;this reference&amp;nbsp;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
using make command we can build the configuration, but this command is interactive, its ask more than 1000 question about&amp;nbsp;enable&amp;nbsp;or disable the particular module, like which&amp;nbsp;file-system&amp;nbsp;r u want and IP-Tables related&amp;nbsp;modules&amp;nbsp;like SIP components (state-full&amp;nbsp;inspection firewall).&lt;br /&gt;
&lt;br /&gt;
so the best way is copy the current Linux config file. its stored in /boot/config-&amp;lt;version&amp;gt;.&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;cp /boot/config-&lt;/b&gt;&lt;b&gt;2.6.35.22-generic &amp;nbsp; &amp;nbsp; &amp;nbsp;.config&lt;/b&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
now we got old configuration. now we change/add new configuration settings.&lt;br /&gt;
for this purpose therse is lots of options are avialable&lt;br /&gt;
&lt;b style="background-color: #fff2cc;"&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b style="background-color: #fff2cc;"&gt;make help&lt;/b&gt;&lt;b style="background-color: #fff2cc;"&gt;&amp;nbsp; &amp;nbsp;&lt;/b&gt;&amp;nbsp; &amp;nbsp; ==&amp;gt;Provides the help&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #990000;"&gt;There is GUI&amp;nbsp;option&amp;nbsp;is also&amp;nbsp;available&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #990000;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;
&lt;b style="background-color: #fff2cc;"&gt;make &amp;nbsp; menuconfig &amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;b style="background-color: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; ==&amp;gt; this provides Text based GUI&amp;nbsp;&lt;/b&gt;&lt;b style="background-color: white;"&gt;Configuration&lt;/b&gt;&lt;br /&gt;
&lt;b style="background-color: white;"&gt;&lt;br /&gt;&lt;/b&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-YrXAfpUms4g/T5FL4LnKeRI/AAAAAAAACKw/5sUvVfHIJkc/s1600/snapshot1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="286" src="http://4.bp.blogspot.com/-YrXAfpUms4g/T5FL4LnKeRI/AAAAAAAACKw/5sUvVfHIJkc/s400/snapshot1.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
here load the old config file and add/change the settings then save the config file.&lt;br /&gt;
&lt;br /&gt;
&lt;b style="background-color: #fff2cc;"&gt;make &amp;nbsp; gconfig&amp;nbsp;&lt;/b&gt;&lt;b style="background-color: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;==&amp;gt; this provides GTK 2 based GUI Configuration for GNOME&lt;/b&gt;&lt;br /&gt;
&lt;b style="background-color: white;"&gt;&lt;br /&gt;&lt;/b&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-6e-hTFPXIhM/T5FL2I-da1I/AAAAAAAACKg/QVBD97NEPfU/s1600/gconfig.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="267" src="http://2.bp.blogspot.com/-6e-hTFPXIhM/T5FL2I-da1I/AAAAAAAACKg/QVBD97NEPfU/s400/gconfig.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;f&lt;/b&gt;or this we need to install&lt;b&gt; libgtk2.0-dev, libglad2-dev &lt;/b&gt;through apt-get install&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b style="background-color: #fff2cc;"&gt;make &amp;nbsp; xconfig&amp;nbsp;&lt;/b&gt;&lt;b style="background-color: white;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;==&amp;gt; this provides QT based GUI Configuration for KDE&lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-m6Onxy4ErJU/T5FL6pgEXFI/AAAAAAAACLA/sASX8eU-qFk/s1600/xconfig.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://3.bp.blogspot.com/-m6Onxy4ErJU/T5FL6pgEXFI/AAAAAAAACLA/sASX8eU-qFk/s400/xconfig.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;b style="background-color: white;"&gt;&lt;br /&gt;&lt;/b&gt;
&lt;span style="background-color: white;"&gt;for this we need qt-dev tools&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Using any one of the above method modify the&amp;nbsp;configuration.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #990000;"&gt;Step 3 : Compile the Kernel&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; There are two ways to compile the kernel&lt;br /&gt;
&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;Generic way (lots of steps)&lt;/li&gt;
&lt;li&gt;Debian&amp;nbsp;specific way (simple, Use make-kpkg tool)&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #990000;"&gt;&lt;u&gt;Step 3.1 : Generic Way&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;b&gt;&amp;nbsp;&lt;span style="color: magenta;"&gt; Step 3.1.1 Compile the&amp;nbsp;Kernel&amp;nbsp;and its modules&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;b style="background-color: #fff2cc;"&gt;make &amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;above code is take 1 to 2 hours depending on system performance. In this step it compile the kernel and store the&amp;nbsp;kernel&amp;nbsp;in binary form to &lt;b&gt;arch/x86/boot/&lt;/b&gt;&lt;b&gt;bzImage&amp;nbsp;&lt;/b&gt;file&lt;br /&gt;
then based on&amp;nbsp;kernel headers&amp;nbsp;it will compile the&amp;nbsp;kernel&amp;nbsp; modules (device driver, file-system, network,...)&lt;br /&gt;
and generate .ko files. ko means kernel object. These modules also called Loadable Kernel Modules (LKM).&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&lt;b&gt;&lt;span style="color: magenta;"&gt;&amp;nbsp;Step 3.1.2 Install Kernel modules&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;b style="background-color: #fff2cc;"&gt;make &amp;nbsp;modules_install&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;This step copy the all kernel&amp;nbsp;modules (*.ko)&amp;nbsp;to&amp;nbsp;&lt;b style="background-color: #f4cccc;"&gt;/lib/modules/&amp;lt;version&amp;gt;/kernel/&lt;/b&gt;&amp;nbsp; &amp;nbsp;folder.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &lt;span style="color: #674ea7;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;b&gt;&lt;span style="color: magenta;"&gt;&amp;nbsp;Step 3.1.3 Install Kernel&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;b style="background-color: #fff2cc;"&gt;make &amp;nbsp;install&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;This step copy the the kenel from&amp;nbsp;&lt;b&gt;arch/x86/boot/bzImage&amp;nbsp;&lt;/b&gt;to&lt;b&gt; /boot &lt;/b&gt;folder and copy the&lt;b&gt; .config&lt;/b&gt; file to &lt;b&gt;/boot/config-&amp;lt;latest-version&amp;gt;&lt;/b&gt; and generate the&amp;nbsp;&lt;b&gt;System.map &lt;/b&gt;file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style="color: #674ea7;"&gt;&amp;nbsp;&lt;/span&gt;&lt;b&gt;&lt;span style="color: magenta;"&gt;&amp;nbsp;Step 3.1.4 Create Initramfs file&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style="color: magenta; font-weight: bold;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;up to&amp;nbsp;now kernel and its modules are compiled and installed. when next boot up time we need to choose latest kernel. so we need to prepare the boot-loader and its support files. When system turns on, after bios and boot loader load the kernel to main memory and mount initial dummy&amp;nbsp;file system&amp;nbsp;as a root file system of system. this initial file system have necessary drivers for disk hardware (SCSI or IDE) and mount the correct file system as a root file system.&lt;br /&gt;
&lt;br /&gt;
so we need to create initramfs file using update-initramfs or mkinitfs tool&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;b style="background-color: #fff2cc;"&gt;&amp;nbsp;update-initramfs&amp;nbsp;-c -k 3.3.3&lt;/b&gt;&lt;br /&gt;
here 3.3.3 is new kernel version.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&lt;b&gt;&lt;span style="color: magenta;"&gt;Step 3.1.5 &amp;nbsp;Update GRUB bootloader&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; the last step is update the boot loader here i m using GRUB boot-loader.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;b style="background-color: #fff2cc;"&gt;&amp;nbsp;update-grub&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
this command automatically probe the kernels in &lt;b&gt;/boot&lt;/b&gt; folder and add the entries in its configuration file, &lt;b&gt;grub.cfg&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
now restart the system , we will see the new kernel is added in boot loader entries. then choose new kernel in boot loader.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-RPM3M0gpFeM/T5FL3JLNOCI/AAAAAAAACKk/PnhMQMfWdxk/s1600/grub.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="295" src="http://2.bp.blogspot.com/-RPM3M0gpFeM/T5FL3JLNOCI/AAAAAAAACKk/PnhMQMfWdxk/s400/grub.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
now open the terminal and issue&lt;b style="background-color: #fff2cc;"&gt; uname -r&lt;/b&gt; command, its shows the &amp;nbsp;current kernel version.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-cujdCiZE3no/T5FL05Oe0yI/AAAAAAAACKY/vUGLB2ACtAo/s1600/after.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="96" src="http://3.bp.blogspot.com/-cujdCiZE3no/T5FL05Oe0yI/AAAAAAAACKY/vUGLB2ACtAo/s400/after.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #990000;"&gt;&lt;u&gt;Step 3.2 :&amp;nbsp;Debian&amp;nbsp;specific way&amp;nbsp;Way&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; In Debian system's (Ubuntu, Linux Mint,..) there is one&amp;nbsp;tool "&lt;b&gt;make-kpkg&lt;/b&gt;"&amp;nbsp;is&amp;nbsp;available&amp;nbsp;to automate the kernel compilation process.&lt;br /&gt;
&lt;br /&gt;
to install the make-kpkg, use apt-get&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;sudo apt-get install &amp;nbsp; &amp;nbsp;kernel-package &amp;nbsp; &amp;nbsp;libncurses5-dev&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
this one line command is compile the kernel and its modules and make the binary form in deb file.&lt;br /&gt;
&lt;b style="background-color: #fff2cc;"&gt;make-kpkg --initrd --append-to-version=-ramki &amp;nbsp; &amp;nbsp;kernel_image &amp;nbsp; &amp;nbsp; kernel_headers&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
this one line make the kernel and its headers with custom suffix &lt;b&gt;-ramki&lt;/b&gt;&lt;br /&gt;
&lt;span style="color: purple;"&gt;&lt;b&gt;--initrd &lt;/b&gt;&lt;/span&gt;specify that make initramfs disk file&lt;br /&gt;
&lt;span style="color: purple;"&gt;&lt;b&gt;kernel_image&lt;/b&gt;&lt;/span&gt; option to make the kernel and its modules&lt;br /&gt;
&lt;b&gt;&lt;span style="color: purple;"&gt;kernel_headers&lt;/span&gt;&lt;/b&gt; option to make all header files of the kernel. &lt;b&gt;(optional)&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
the final output is its create 2 DEB files.&lt;br /&gt;
&lt;br /&gt;
Install the Deb files&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; Install the deb file is simple. use dpkg tool like normal installation in&amp;nbsp;Debian&amp;nbsp;system&lt;br /&gt;
&lt;b style="background-color: #fff2cc;"&gt;dpkg -i kernel_image-ramki-i386.deb&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
while executing this line install the kernel to &lt;b&gt;/boot&lt;/b&gt; folder. install the modules in &lt;b&gt;/lib/modules&lt;/b&gt; folder and create the &lt;b&gt;initramfs&lt;/b&gt; file and update the grub like generic way. all the above operation is happen automatically.&lt;br /&gt;
&lt;br /&gt;
then in optional case we can install the kernel_headers-ramki-i386.deb file.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #660000;"&gt;why need the kernel headers are important?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;kernel_image is enough to run the system. but when we need to install drivers, for example we need to install the new driver in&amp;nbsp;Linux&amp;nbsp; that time while compile the driver, that time need the&amp;nbsp;kernel&amp;nbsp;headers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In my system its works fine. i tested in VM also.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #660000;"&gt;Reference:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;&lt;a href="http://www.howtoforge.com/kernel_compilation_ubuntu" target="_blank"&gt;How To Compile A Kernel - The Ubuntu Way&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.cyberciti.biz/tips/compiling-linux-kernel-26.html" target="_blank"&gt;How to: Compile Linux kernel 2.6&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #990000;"&gt;Comments Welcomed&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;style&gt;
.adslot-overlay {position: absolute; font-family: arial, sans-serif; background-color: rgba(0,0,0,0.65); border: 2px solid rgba(0,0,0,0.65); color: white !important; margin: 0; z-index: 2147483647; text-decoration: none; box-sizing: border-box; text-align: left;}.adslot-overlay-iframed {top: 0; left: 0; right: 0; bottom: 0;}.slotname {position: absolute; top: 0; left: 0; right: 0; font-size: 13px; font-weight: bold; padding: 3px 0 3px 6px; vertical-align: middle; background-color: rgba(0,0,0,0.45); text-overflow: ellipsis; white-space: nowrap; overflow: hidden;}.slotname span {text-align: left; text-decoration: none; text-transform: capitalize;}.revenue {position: absolute; bottom: 0; left: 0; right: 0; font-size: 11px; padding: 3px 0 3px 6px; vertial-align: middle; text-align: left; background-color: rgba(0,0,0,0.45); font-weight: bold; text-overflow: ellipsis; overflow: hidden; white-space: nowrap;}.revenue .name {color: #ccc;}.revenue .horizontal .metric {display: inline-block; padding-right: 1.5em;}.revenue .horizontal .name {padding-right: 0.5em;}.revenue .vertical .metric {display: block; line-height: 1.5em; margin-bottom: 0.5em;}.revenue .vertical .name, .revenue .vertical .value {display: block;}.revenue .square .metric, .revenue .button .metric {display: table-row;}.revenue .square .metric {line-height: 1.5em;}.revenue .square .name, .revenue .square .value, .revenue .button .value {display: table-cell;}.revenue .square .name {padding-right: 1.5em;}.revenue .button .name {display: block; margin-right: 0.5em; width: 1em; overflow: hidden; text-overflow: clip;}.revenue .button .name:first-letter {margin-right: 1.5em;}a.adslot-overlay:hover {border: 2px solid rgba(58,106,173,0.9);}a.adslot-overlay:hover .slotname {border-bottom: 1px solid rgba(81,132,210,0.9); background-color: rgba(58,106,173,0.9);}a.adslot-overlay:hover .revenue {border-top: 1px solid rgba(81,132,210,0.9); background-color: rgba(58,106,173,0.9);}div.adslot-overlay:hover {cursor: not-allowed; border: 2px solid rgba(64,64,64,0.9);}div.adslot-overlay:hover .slotname {border-bottom: 1px solid rgba(128,128,128,0.9); background-color: rgba(64,64,64,0.9);}div.adslot-overlay:hover .revenue {border-top: 1px solid rgba(128,128,128,0.9); background-color: rgba(64,64,64,0.9);}
&lt;/style&gt;&lt;/div&gt;
&lt;div&gt;
&lt;style&gt;
.adslot-overlay {position: absolute; font-family: arial, sans-serif; background-color: rgba(0,0,0,0.65); border: 2px solid rgba(0,0,0,0.65); color: white !important; margin: 0; z-index: 2147483647; text-decoration: none; box-sizing: border-box; text-align: left;}.adslot-overlay-iframed {top: 0; left: 0; right: 0; bottom: 0;}.slotname {position: absolute; top: 0; left: 0; right: 0; font-size: 13px; font-weight: bold; padding: 3px 0 3px 6px; vertical-align: middle; background-color: rgba(0,0,0,0.45); text-overflow: ellipsis; white-space: nowrap; overflow: hidden;}.slotname span {text-align: left; text-decoration: none; text-transform: capitalize;}.revenue {position: absolute; bottom: 0; left: 0; right: 0; font-size: 11px; padding: 3px 0 3px 6px; vertial-align: middle; text-align: left; background-color: rgba(0,0,0,0.45); font-weight: bold; text-overflow: ellipsis; overflow: hidden; white-space: nowrap;}.revenue .name {color: #ccc;}.revenue .horizontal .metric {display: inline-block; padding-right: 1.5em;}.revenue .horizontal .name {padding-right: 0.5em;}.revenue .vertical .metric {display: block; line-height: 1.5em; margin-bottom: 0.5em;}.revenue .vertical .name, .revenue .vertical .value {display: block;}.revenue .square .metric, .revenue .button .metric {display: table-row;}.revenue .square .metric {line-height: 1.5em;}.revenue .square .name, .revenue .square .value, .revenue .button .value {display: table-cell;}.revenue .square .name {padding-right: 1.5em;}.revenue .button .name {display: block; margin-right: 0.5em; width: 1em; overflow: hidden; text-overflow: clip;}.revenue .button .name:first-letter {margin-right: 1.5em;}a.adslot-overlay:hover {border: 2px solid rgba(58,106,173,0.9);}a.adslot-overlay:hover .slotname {border-bottom: 1px solid rgba(81,132,210,0.9); background-color: rgba(58,106,173,0.9);}a.adslot-overlay:hover .revenue {border-top: 1px solid rgba(81,132,210,0.9); background-color: rgba(58,106,173,0.9);}div.adslot-overlay:hover {cursor: not-allowed; border: 2px solid rgba(64,64,64,0.9);}div.adslot-overlay:hover .slotname {border-bottom: 1px solid rgba(128,128,128,0.9); background-color: rgba(64,64,64,0.9);}div.adslot-overlay:hover .revenue {border-top: 1px solid rgba(128,128,128,0.9); background-color: rgba(64,64,64,0.9);}
&lt;/style&gt;&lt;/div&gt;
&lt;div&gt;
&lt;style&gt;
.adslot-overlay {position: absolute; font-family: arial, sans-serif; background-color: rgba(0,0,0,0.65); border: 2px solid rgba(0,0,0,0.65); color: white !important; margin: 0; z-index: 2147483647; text-decoration: none; box-sizing: border-box; text-align: left;}.adslot-overlay-iframed {top: 0; left: 0; right: 0; bottom: 0;}.slotname {position: absolute; top: 0; left: 0; right: 0; font-size: 13px; font-weight: bold; padding: 3px 0 3px 6px; vertical-align: middle; background-color: rgba(0,0,0,0.45); text-overflow: ellipsis; white-space: nowrap; overflow: hidden;}.slotname span {text-align: left; text-decoration: none; text-transform: capitalize;}.revenue {position: absolute; bottom: 0; left: 0; right: 0; font-size: 11px; padding: 3px 0 3px 6px; vertial-align: middle; text-align: left; background-color: rgba(0,0,0,0.45); font-weight: bold; text-overflow: ellipsis; overflow: hidden; white-space: nowrap;}.revenue .name {color: #ccc;}.revenue .horizontal .metric {display: inline-block; padding-right: 1.5em;}.revenue .horizontal .name {padding-right: 0.5em;}.revenue .vertical .metric {display: block; line-height: 1.5em; margin-bottom: 0.5em;}.revenue .vertical .name, .revenue .vertical .value {display: block;}.revenue .square .metric, .revenue .button .metric {display: table-row;}.revenue .square .metric {line-height: 1.5em;}.revenue .square .name, .revenue .square .value, .revenue .button .value {display: table-cell;}.revenue .square .name {padding-right: 1.5em;}.revenue .button .name {display: block; margin-right: 0.5em; width: 1em; overflow: hidden; text-overflow: clip;}.revenue .button .name:first-letter {margin-right: 1.5em;}a.adslot-overlay:hover {border: 2px solid rgba(58,106,173,0.9);}a.adslot-overlay:hover .slotname {border-bottom: 1px solid rgba(81,132,210,0.9); background-color: rgba(58,106,173,0.9);}a.adslot-overlay:hover .revenue {border-top: 1px solid rgba(81,132,210,0.9); background-color: rgba(58,106,173,0.9);}div.adslot-overlay:hover {cursor: not-allowed; border: 2px solid rgba(64,64,64,0.9);}div.adslot-overlay:hover .slotname {border-bottom: 1px solid rgba(128,128,128,0.9); background-color: rgba(64,64,64,0.9);}div.adslot-overlay:hover .revenue {border-top: 1px solid rgba(128,128,128,0.9); background-color: rgba(64,64,64,0.9);}
&lt;/style&gt;&lt;/div&gt;
&lt;div&gt;
&lt;style&gt;
.adslot-overlay {position: absolute; font-family: arial, sans-serif; background-color: rgba(0,0,0,0.65); border: 2px solid rgba(0,0,0,0.65); color: white !important; margin: 0; z-index: 2147483647; text-decoration: none; box-sizing: border-box; text-align: left;}.adslot-overlay-iframed {top: 0; left: 0; right: 0; bottom: 0;}.slotname {position: absolute; top: 0; left: 0; right: 0; font-size: 13px; font-weight: bold; padding: 3px 0 3px 6px; vertical-align: middle; background-color: rgba(0,0,0,0.45); text-overflow: ellipsis; white-space: nowrap; overflow: hidden;}.slotname span {text-align: left; text-decoration: none; text-transform: capitalize;}.revenue {position: absolute; bottom: 0; left: 0; right: 0; font-size: 11px; padding: 3px 0 3px 6px; vertial-align: middle; text-align: left; background-color: rgba(0,0,0,0.45); font-weight: bold; text-overflow: ellipsis; overflow: hidden; white-space: nowrap;}.revenue .name {color: #ccc;}.revenue .horizontal .metric {display: inline-block; padding-right: 1.5em;}.revenue .horizontal .name {padding-right: 0.5em;}.revenue .vertical .metric {display: block; line-height: 1.5em; margin-bottom: 0.5em;}.revenue .vertical .name, .revenue .vertical .value {display: block;}.revenue .square .metric, .revenue .button .metric {display: table-row;}.revenue .square .metric {line-height: 1.5em;}.revenue .square .name, .revenue .square .value, .revenue .button .value {display: table-cell;}.revenue .square .name {padding-right: 1.5em;}.revenue .button .name {display: block; margin-right: 0.5em; width: 1em; overflow: hidden; text-overflow: clip;}.revenue .button .name:first-letter {margin-right: 1.5em;}a.adslot-overlay:hover {border: 2px solid rgba(58,106,173,0.9);}a.adslot-overlay:hover .slotname {border-bottom: 1px solid rgba(81,132,210,0.9); background-color: rgba(58,106,173,0.9);}a.adslot-overlay:hover .revenue {border-top: 1px solid rgba(81,132,210,0.9); background-color: rgba(58,106,173,0.9);}div.adslot-overlay:hover {cursor: not-allowed; border: 2px solid rgba(64,64,64,0.9);}div.adslot-overlay:hover .slotname {border-bottom: 1px solid rgba(128,128,128,0.9); background-color: rgba(64,64,64,0.9);}div.adslot-overlay:hover .revenue {border-top: 1px solid rgba(128,128,128,0.9); background-color: rgba(64,64,64,0.9);}
&lt;/style&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=vUVdI2EJ-qM:HEkjaPav0W4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=vUVdI2EJ-qM:HEkjaPav0W4:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=vUVdI2EJ-qM:HEkjaPav0W4:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?i=vUVdI2EJ-qM:HEkjaPav0W4:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=vUVdI2EJ-qM:HEkjaPav0W4:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ramki/feeds/~4/vUVdI2EJ-qM" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ramki/feeds/~3/vUVdI2EJ-qM/how-to-compile-kernel-step-by-step.html</link><author>noreply@blogger.com (Rama krishnnan E P)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-VwizV9ywLPA/T5FL5ibXkmI/AAAAAAAACK0/JJtMFWHudUg/s72-c/uname.png" height="72" width="72" /><georss:featurename>Unknown location.</georss:featurename><georss:point>33.43144133557529 -67.5</georss:point><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /><feedburner:origLink>http://www.ramkitech.com/2012/04/how-to-compile-kernel-step-by-step.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-5609480529308880140</guid><pubDate>Tue, 20 Mar 2012 07:45:00 +0000</pubDate><atom:updated>2013-02-12T15:21:55.274+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">mod_jk</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">apache</category><category domain="http://www.blogger.com/atom/ns#">virtual hosting</category><category domain="http://www.blogger.com/atom/ns#">Tomcat</category><title>Virtual Host + Apache httpd server + Tomcat + mod_jk connector</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
In my last post (&lt;a href="http://www.ramkitech.com/2012/02/understanding-virtual-host-concept-in.html" target="_blank"&gt;Virtual Host in Tomcat&lt;/a&gt;) we discussed about how setup the&amp;nbsp;virtual&amp;nbsp;host in Tomcat. Its cost effective&amp;nbsp;technique&amp;nbsp;because only one public IP is&amp;nbsp;enough&amp;nbsp;to host multiple domain. If we have big organization and each department want to host their website in locally in different machine. then how to&amp;nbsp;achieve&amp;nbsp;the virtual host concept?. In this post we will see the how we do this.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style="background-color: white;"&gt;&lt;b&gt;&lt;span style="color: red;"&gt;Update : &amp;nbsp;&lt;/span&gt;&lt;/b&gt;I posted&amp;nbsp;&lt;a href="http://www.ramkitech.com/2013/02/virtual-host-nginx-tomcat.html" target="_blank"&gt;Virtual Host&amp;nbsp;+ Nginx&amp;nbsp;+ Tomcat&lt;/a&gt;&amp;nbsp;Its easy to configure, compare to Apache httpd server&lt;/span&gt;&lt;/h3&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: purple; font-size: large;"&gt;&lt;b&gt;Problem Scenario:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; In big organization they have multiple department, each department want to host their website in different machine. so these websites are accessed locally with different local IP address.&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-TLyyrW-Wk6Y/T2gOrugVt0I/AAAAAAAAB_k/7kyCrNCHl3s/s1600/outline_structure.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="427" src="http://1.bp.blogspot.com/-TLyyrW-Wk6Y/T2gOrugVt0I/AAAAAAAAB_k/7kyCrNCHl3s/s640/outline_structure.jpg" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
When we mapping to public address then we face the problem. We have two choice either purchase as many public&amp;nbsp;address&amp;nbsp;or Put one server front &amp;nbsp;and delegate these request.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;We going to use 2nd option. we put&amp;nbsp;Apache&amp;nbsp;httpd web server in front of all department servers. so only one public IP is enough. All domain DNS&amp;nbsp;entries&amp;nbsp;are pointed to Apache httpd server. Then Apache server delegates these request to corresponding tomcat server. This process is completely transparent from users(browser) perspective.&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-wWtKl_9eNvA/T2gOtW0LCVI/AAAAAAAAB_0/weXELW0y8ag/s1600/virtual_host_apache_and_tomcat_outline.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="414" src="http://4.bp.blogspot.com/-wWtKl_9eNvA/T2gOtW0LCVI/AAAAAAAAB_0/weXELW0y8ag/s640/virtual_host_apache_and_tomcat_outline.jpg" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Outline Structure of Virtual Host Implementation&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;b&gt;&lt;span style="color: purple; font-size: large;"&gt;How Apache httpd web server communicate to Tomcat server&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Before we going to detail about how communication happen between httpd server and tomcat&lt;br /&gt;
&lt;br /&gt;
How many ports are bind when we start single tomcat?&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;shutdown port&lt;/li&gt;
&lt;li&gt;http connector port&lt;/li&gt;
&lt;li&gt;https connector port (optional)&lt;/li&gt;
&lt;li&gt;ajp port&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
The port configuration are stored in $CATALINA_HOME/conf/server.xml file. we can change the ports when its&amp;nbsp;necessary.&lt;br /&gt;
&lt;br /&gt;
here AJP&lt;b&gt;(&lt;/b&gt;&lt;span style="background-color: white;"&gt;&lt;b&gt;Apache JServ Protocol)&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&amp;nbsp;is a binary protocol that can proxy inbound requests from a web server through to an application server that sits behind the web server.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;Apache httpd webserver&amp;nbsp;communicate&amp;nbsp;to Tomcat sever through &lt;b&gt;AJP&lt;/b&gt; protocol&lt;/span&gt;.&lt;br /&gt;
&lt;br /&gt;
When we install&amp;nbsp;Apache&amp;nbsp;httpd server, It&amp;nbsp;don't&amp;nbsp;have&amp;nbsp;inbuilt&amp;nbsp;capability to support ajp protocol. so we need &lt;b&gt;mod_jk&lt;/b&gt; module. Its add the ajp support to&amp;nbsp;Apache&amp;nbsp;httpd server.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: purple; font-size: large;"&gt;Steps to Implement Virtual Host Concept in this Scenario:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Install Apache httpd Web Server&lt;/li&gt;
&lt;li&gt;Install mod_jk connector&lt;/li&gt;
&lt;li&gt;Configure JK Connector&lt;/li&gt;
&lt;li&gt;Configure Apache httpd server apply virtual host concepts&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;b&gt;Prerequisite&lt;/b&gt; : We already installed Tomcat in different departments and&amp;nbsp;deployed&amp;nbsp;the application and works fine.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #990000; font-size: large;"&gt;&lt;b&gt;Install Apache httpd web&amp;nbsp;server&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #990000; font-size: xx-small;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;We can install&amp;nbsp;Apache&amp;nbsp;web server in two ways.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- Binary module&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- From Source&lt;br /&gt;
&lt;br /&gt;
We can install Apache httpd server from distribution&amp;nbsp;package&amp;nbsp;manager (either apt-get or yum). Or we can download the source code and then compile and install.&lt;br /&gt;
&lt;br /&gt;
we use second option. First download the httpd server source code from &lt;a href="http://httpd.apache.org/" target="_blank"&gt;here&lt;/a&gt;&amp;nbsp;. then extract it and install&lt;br /&gt;
&lt;br /&gt;
&lt;b style="background-color: #fff2cc;"&gt;./configure --prefix=/usr/local/apache&lt;/b&gt;&lt;b style="background-color: #fff2cc;"&gt;&amp;nbsp; &amp;nbsp; --enable-rewrite=shared&amp;nbsp;&lt;/b&gt;&lt;b style="background-color: #fff2cc;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;--enable-proxy=shared&lt;/b&gt;&lt;br /&gt;
&lt;b style="background-color: #fff2cc;"&gt;make&lt;/b&gt;&lt;br /&gt;
&lt;b style="background-color: #fff2cc;"&gt;sudo make install&lt;/b&gt;&lt;br /&gt;
&lt;b style="background-color: #fff2cc;"&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;div&gt;
here&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;&lt;b style="background-color: #fff2cc;"&gt;--prefix&lt;/b&gt;&amp;nbsp;option to mention where the location we going to install&amp;nbsp;Apache&amp;nbsp;httpd server.&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;&amp;nbsp;--enable-rewrite&lt;/b&gt;&amp;nbsp;and&amp;nbsp;&lt;b style="background-color: #fff2cc;"&gt;--enable-proxy &lt;/b&gt;options to enable these module in shared mode. These modules&amp;nbsp;are&amp;nbsp;not needed now. but we used in future for rewrite the&amp;nbsp;URL&amp;nbsp;before handover to next chain of servers and load-balancing support.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="color: #990000; font-size: x-large;"&gt;Install mod_jk connector&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;Now&amp;nbsp;Apache&amp;nbsp;httpd server is ready. we&amp;nbsp;need&amp;nbsp;to add ajp support to server.&lt;b style="color: #990000; font-size: x-large;"&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
download the mod_jk connector module from &lt;a href="http://tomcat.apache.org/download-connectors.cgi" target="_blank"&gt;here&lt;/a&gt;. extract it and install it&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;cd native&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style="background-color: #fff2cc;"&gt;./configure &amp;nbsp; &amp;nbsp;-&lt;/span&gt;&lt;span style="background-color: #fff2cc;"&gt;-with-apxs=/usr/local/apache/bin/apxs&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;make&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;sudo make install&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
here&amp;nbsp;&lt;b&gt;&lt;span style="background-color: #fff2cc;"&gt;&amp;nbsp;-&lt;/span&gt;&lt;span style="background-color: #fff2cc;"&gt;-with-apxs&lt;/span&gt;&lt;/b&gt;&amp;nbsp;option to specify where apxs module is located. so we&amp;nbsp;need&amp;nbsp;to give&amp;nbsp;Apache&amp;nbsp;httpd server location.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
now&lt;span style="background-color: #fce5cd;"&gt;&amp;nbsp;mod_jk.so&lt;/span&gt; files is created on modules directory in apache installed location (/usr/local/apache/modules)&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;!-- adsense --&gt;&lt;br /&gt;
&lt;div&gt;
&lt;b style="color: #990000; font-size: x-large;"&gt;Configure mod_jk connector&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
This step have 2 sub step&lt;/div&gt;
&lt;div&gt;
&lt;ul&gt;
&lt;li&gt;&amp;nbsp; Create workers.properties file&lt;/li&gt;
&lt;li&gt;&amp;nbsp; &amp;nbsp;Load and configure the JK connector module in apache httpd.conf file&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style="color: #4c1130;"&gt;Create workers.properties file&lt;/span&gt;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
mod_jk connector is ready. but this connector is works based on configuration file. so we need to create configuration file called&lt;b style="background-color: #fff2cc;"&gt; workers.properties&lt;/b&gt; file&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
this file syntax is&lt;span style="background-color: #fce5cd;"&gt; key=value&lt;/span&gt;&amp;nbsp;pair,&lt;/div&gt;
&lt;div&gt;
here we define the workers. i.e all department tomcat hosts IP address and ajp port for corressponding tomcat.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
here entry format is look like&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;worker&lt;span style="color: #20124d;"&gt;.&lt;/span&gt;&lt;span style="color: #cc0000;"&gt;&amp;lt;name&amp;gt;&lt;/span&gt;.property=&lt;span style="color: #cc0000;"&gt;&amp;lt;value&amp;gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
for example&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
worker.&amp;lt;name&amp;gt;.type=ajp13&lt;/div&gt;
&lt;div&gt;
worker.&amp;lt;name&amp;gt;.port=&amp;lt;ajp port&amp;gt;&lt;/div&gt;
&lt;div&gt;
worker.&amp;lt;name&amp;gt;.host=&amp;lt;tomcat ip addr&amp;gt;&lt;/div&gt;
&lt;div&gt;
worker.list=&amp;lt;name&amp;gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
here&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
worker.list key have all workers name&amp;nbsp;separated&amp;nbsp;by comma.&lt;/div&gt;
&lt;div&gt;
type = here type of the worker. we use ajp13 version&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
port= we specify the ajp port &lt;b&gt;&lt;span style="color: #660000;"&gt;(not http port )&lt;/span&gt;&lt;/b&gt; of that server&lt;/div&gt;
&lt;div&gt;
host= IP address or host name of tomcat server&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;&lt;u&gt;workers.properties&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: #d9ead3;"&gt;&lt;b&gt;&lt;span style="color: blue;"&gt;worker.list=department1,department2,department3&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: #d9ead3;"&gt;&lt;b&gt;&lt;span style="color: blue;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style="background-color: #d9ead3;"&gt;&lt;b&gt;&lt;span style="color: blue;"&gt;worker.department1.type=ajp13&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: #d9ead3;"&gt;&lt;b&gt;&lt;span style="color: blue;"&gt;worker.department1.port=5000&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: #d9ead3;"&gt;&lt;b&gt;&lt;span style="color: blue;"&gt;worker.department1.host=192.168.5.10&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: #d9ead3;"&gt;&lt;b&gt;&lt;span style="color: blue;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style="background-color: #d9ead3;"&gt;&lt;b&gt;&lt;span style="color: blue;"&gt;worker.department2.type=ajp13&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: #d9ead3;"&gt;&lt;b&gt;&lt;span style="color: blue;"&gt;worker.department2.port=5000&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: #d9ead3;"&gt;&lt;b&gt;&lt;span style="color: blue;"&gt;worker.department2.host=192.168.6.10&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;span style="background-color: #d9ead3;"&gt;&lt;b&gt;&lt;span style="color: blue;"&gt;&lt;br class="Apple-interchange-newline" /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style="background-color: #d9ead3;"&gt;&lt;b&gt;&lt;span style="color: blue;"&gt;worker.department3.type=ajp13&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: #d9ead3;"&gt;&lt;b&gt;&lt;span style="color: blue;"&gt;worker.department3.port=5000&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: #d9ead3;"&gt;&lt;b&gt;&lt;span style="color: blue;"&gt;worker.department3.host=192.168.7.10&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: #d9ead3;"&gt;&lt;b&gt;&lt;span style="color: blue;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style="color: #990000; font-size: large;"&gt;Add Entry in httpd.conf&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
Apache httpd server is installed. mod_jk module is installed and&amp;nbsp;workers.properties file is created. but these 3 are isolated. we put together,&lt;br /&gt;
we need to configure the httpd server.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
find the&lt;b&gt;&lt;span style="color: #fff2cc;"&gt; &lt;/span&gt;&lt;span style="background-color: #fce5cd;"&gt;conf/httpd.conf&lt;/span&gt;&lt;/b&gt; file in&amp;nbsp;Apache&amp;nbsp;installed location and add these following entries to it&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;LoadModule &amp;nbsp; &amp;nbsp;jk_module &amp;nbsp;modules/mod_jk.so&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;JkWorkersFile conf/workers.properties&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;JkLogFile &amp;nbsp; &amp;nbsp; logs/mod_jk.log&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;JkLogLevel &amp;nbsp; &amp;nbsp;emerg&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;JkOptions &amp;nbsp; &amp;nbsp; +ForwardKeySize +ForwardURICompat -ForwardDirectories&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;JkRequestLogFormat &amp;nbsp; &amp;nbsp; "%w %V %T"&lt;/b&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
here&lt;/div&gt;
&lt;div&gt;
LoadModule &amp;nbsp; &amp;nbsp;- Load mod_jk shared module to Apache httpd server (enable the mod_jk module)&lt;/div&gt;
JkWorkersFile -&amp;nbsp;Specify&amp;nbsp;the workers.properties file location&lt;/div&gt;
&lt;div&gt;
all others are logging system of mod_jk. Its&amp;nbsp;boilerplate&amp;nbsp;code just copy and paste.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #990000; font-size: large;"&gt;&lt;b&gt;Delegate httpd to Tomcat&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
now we inform to Apache httpd server how delegate the request to corresponding server.&lt;span style="color: #990000; font-size: large;"&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;JkMount &amp;nbsp;/department1*&amp;nbsp;&lt;/b&gt;&lt;b&gt;&lt;span style="color: blue;"&gt;department1&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;JkMount &amp;nbsp;/department2* &lt;/b&gt;&lt;b&gt;&lt;span style="color: blue;"&gt;department2&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;JkMount &amp;nbsp;/department3*&amp;nbsp;&lt;/b&gt;&lt;b&gt;&lt;span style="color: blue;"&gt;department3&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
here&lt;/div&gt;
&lt;div&gt;
JkMount -&amp;nbsp;specify&amp;nbsp;the if URL have /department1* pattern then that request delegate to department1 worker. that worker IP address and port is&amp;nbsp;specified&amp;nbsp;in workers.properties file.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Iwe changed /etc/hosts file like &lt;a href="http://www.ramkitech.com/2012/02/understanding-virtual-host-concept-in.html" style="font-weight: bold;" target="_blank"&gt;last post&amp;nbsp;&lt;/a&gt;&amp;nbsp;all web site domain pointed to apache httpd web server.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
if we access &lt;b&gt;&lt;span style="color: #cc0000;"&gt;http://www.ramki.com/department1/index.html&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&amp;nbsp;how Apache httpd server process the request&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-Mjl4sHW_eks/T2gOurUxLbI/AAAAAAAAB_8/hhAqLLS9P3o/s1600/virtual_host_apache_and_tomcat_processing.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;span style="color: black;"&gt;&lt;img border="0" height="457" src="http://1.bp.blogspot.com/-Mjl4sHW_eks/T2gOurUxLbI/AAAAAAAAB_8/hhAqLLS9P3o/s640/virtual_host_apache_and_tomcat_processing.jpg" width="640" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
Its perfectly called correct tomcat server and we got right response.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
but we have 2 problem&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&amp;nbsp;1.&lt;/b&gt; i don't want the my URL like this&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;b&gt;&lt;span style="color: #cc0000;"&gt;http://www.ramki.com/department1/index.html&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; i want the my URL like this&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;b&gt;&lt;span style="color: #cc0000;"&gt;http://www.ramki.com/index.html&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
remove the department1 from my URL. but&amp;nbsp;department1&amp;nbsp;string is very important in URL because JkMount is works based on this matching string only.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
2.&amp;nbsp;&lt;b&gt;&lt;span style="color: #cc0000;"&gt;http://www.ramki.com/department1/index.html&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&amp;nbsp; is for first tomcat and second department have domain &amp;nbsp; http://www.krishnan.com then&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
access second tomcat we use URL :&amp;nbsp;&lt;b&gt;&lt;span style="color: #cc0000;"&gt;http://www.krishnan.com/department2/index.html&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
but same time when we use&amp;nbsp;URL&lt;span style="color: #cc0000;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;/span&gt;&amp;nbsp;&lt;span style="color: #cc0000; font-weight: bold;"&gt;http://www.krishnan.com/department1/index.html &lt;/span&gt;then we access first tomcat data&lt;/div&gt;
&lt;div&gt;
(i.e&lt;span style="background-color: #fff2cc;"&gt;&amp;nbsp;)&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #cc0000;"&gt;&lt;span style="background-color: #fff2cc;"&gt;http://www.ramki.com/department1/index.html &amp;nbsp;&lt;/span&gt;&lt;span style="background-color: #fce5cd;"&gt;==&lt;/span&gt;&lt;span style="background-color: #fff2cc;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style="background-color: #fff2cc; color: #cc0000; font-weight: bold;"&gt;http://www.krishnan.com/department1/index.html&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
because both these URL have department1 key word.. so JkMount is works based on these keyword. As the Result wrong interpretation. How to solve this Issue?.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style="color: #990000; font-size: large;"&gt;Virtual Host in Apache httpd Server&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
we need add conditional JkMount. for example ramki.com domain asks the whereare paths like&amp;nbsp;department1,department2 we need to search in that tomcat only. not other place. to add this&amp;nbsp;conditioned&amp;nbsp;we add virtual host entries.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Add virtual host entry in &lt;span style="background-color: #fce5cd;"&gt;httpd.conf&lt;/span&gt; file&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;Listen 80&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;NameVirtualHost *:80&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;&amp;lt;VirtualHost *:80&amp;gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;&amp;nbsp; &amp;nbsp; ServerName www.ramki.com&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;&amp;nbsp; &amp;nbsp; JkMount &amp;nbsp;/department1*&amp;nbsp;department1&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;&amp;lt;/VirtualHost&amp;gt;&lt;/b&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;&amp;lt;VirtualHost *:80&amp;gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;&amp;nbsp; &amp;nbsp; ServerName www.krishnan.com&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;&amp;nbsp; &amp;nbsp; JkMount &amp;nbsp;/department2*&amp;nbsp;department1&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;&amp;lt;/VirtualHost&amp;gt;&lt;/b&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
here&lt;/div&gt;
&lt;div&gt;
ServerName - domain name of the server&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
If&amp;nbsp;&amp;nbsp;&lt;span style="color: #cc0000; font-weight: bold;"&gt;http://www.krishnan.com/department1/index.html &lt;/span&gt;URL is like this now. server matches the&amp;nbsp;Server Name. here its matches 2nd virtual host entry. There are single JkMount entry is there in 2nd&amp;nbsp;Virtual-Host. and there&amp;nbsp;no matching&amp;nbsp;department1 string.&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;&lt;b style="background-color: #fff2cc;"&gt;&amp;nbsp;JkMount &amp;nbsp;/department2*&amp;nbsp;department1&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: white;"&gt;as the result 404 error page is responded. Its works good.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: white;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
Now everythig works fine.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
now my URL is&amp;nbsp;&amp;nbsp;&lt;b style="color: #cc0000;"&gt;http://www.ramki.com/department1/index.html &lt;/b&gt;here i don't want department1 path in my URL.&lt;/div&gt;
&lt;div&gt;
i want simply &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style="color: #cc0000; font-weight: bold;"&gt;http://www.ramki.com/index.html &lt;/span&gt;then we use &lt;span style="background-color: #fce5cd;"&gt;&lt;b&gt;mod_rewrite &lt;/b&gt;&lt;/span&gt;engine&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: white;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;Listen 80&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;NameVirtualHost *:80&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;&amp;lt;VirtualHost *:80&amp;gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;&amp;nbsp; &amp;nbsp; &lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;ServerName www.ramki.com&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;     &lt;/span&gt;RewriteEngine on&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;     &lt;/span&gt;RewriteLog logs/apache-mod_rewrite&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;     &lt;/span&gt;RewriteRule ^/(.*)$ /department1/$1 [L,PT]&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;JkMount &amp;nbsp;/* &amp;lt;dept_name&amp;gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;&amp;lt;/VirtualHost&amp;gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style="background-color: white;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style="background-color: white;"&gt;
here&lt;/div&gt;
&lt;div style="background-color: white;"&gt;
&lt;b style="background-color: #fff2cc;"&gt;RewriteEngine on&lt;/b&gt;&amp;nbsp;- Turn on the Rewrite module&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;RewriteRule ^/(.*)$ /department1/$1 [L,PT]&lt;/b&gt;&lt;span style="background-color: white;"&gt;&amp;nbsp; - here&amp;nbsp;&lt;/span&gt;&lt;b style="background-color: #fff2cc;"&gt;^/(.*)$ &lt;/b&gt;&lt;span style="background-color: white;"&gt;its matches any string it capture the value to $1 and change the URL to /department1/$1&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: white;"&gt;i.e&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #cc0000; font-weight: bold;"&gt;http://www.ramki.com/index.html&lt;/span&gt;&amp;nbsp;here&amp;nbsp;&lt;span style="background-color: white;"&gt;&amp;nbsp;&lt;/span&gt;&lt;b style="background-color: #fff2cc;"&gt;^/(.*)$&amp;nbsp;&lt;/b&gt;&lt;span style="background-color: white;"&gt;its&amp;nbsp;&lt;/span&gt;&lt;span style="background-color: white;"&gt;matches&lt;/span&gt;&lt;span style="background-color: white;"&gt;&amp;nbsp; index.html it capture to $1 and&amp;nbsp;replaced&amp;nbsp;to&amp;nbsp;&lt;/span&gt;&lt;span style="background-color: white;"&gt;/department1/$1 ==&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span style="background-color: white;"&gt;/department1/index.html&lt;/span&gt;&lt;span style="background-color: white;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: white;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-NPbEsb2bFpQ/T2gOsqGcbMI/AAAAAAAAB_o/H-Dq1pQHrQs/s1600/virtual_host_apache_and_tomcat_final_processing.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="416" src="http://1.bp.blogspot.com/-NPbEsb2bFpQ/T2gOsqGcbMI/AAAAAAAAB_o/H-Dq1pQHrQs/s640/virtual_host_apache_and_tomcat_final_processing.jpg" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: white;"&gt;Rewrite is happen before delegate the request to Tomcat. so we change the URL transparently to browser.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: white;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: white;"&gt;now client (browser) just send http://www.ramki.com is enough to access the Department 1 Tomcat.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white;"&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style="background-color: white;"&gt;&lt;br /&gt;&lt;/span&gt;
&lt;h3 style="text-align: left;"&gt;
&lt;span style="background-color: white;"&gt;&lt;b&gt;&lt;span style="color: red;"&gt;Update : &amp;nbsp;&lt;/span&gt;&lt;/b&gt;I posted &lt;a href="http://www.ramkitech.com/2013/02/virtual-host-nginx-tomcat.html" target="_blank"&gt;Virtual Host&amp;nbsp;+ Nginx&amp;nbsp;+ Tomcat&lt;/a&gt; Its easy to configure, compare to Apache httpd server&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: white;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style="background-color: #fff2cc;"&gt;I hope everything is clear. If any&amp;nbsp;misunderstanding&amp;nbsp;please&amp;nbsp;let me know.&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: white;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="background-color: white;"&gt;&lt;b&gt;&lt;span style="color: #990000; font-size: large;"&gt;Screen Cast :&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;iframe allowfullscreen="" frameborder="0" height="480" src="http://www.youtube.com/embed/Njx1V4ZW_g0" width="853"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #990000;"&gt;Comments Welcomed&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=b7W46pQ2zAs:EogkZX98Seg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=b7W46pQ2zAs:EogkZX98Seg:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=b7W46pQ2zAs:EogkZX98Seg:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?i=b7W46pQ2zAs:EogkZX98Seg:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=b7W46pQ2zAs:EogkZX98Seg:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ramki/feeds/~4/b7W46pQ2zAs" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ramki/feeds/~3/b7W46pQ2zAs/virtual-host-apache-httpd-server-tomcat.html</link><author>noreply@blogger.com (Rama krishnnan E P)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-TLyyrW-Wk6Y/T2gOrugVt0I/AAAAAAAAB_k/7kyCrNCHl3s/s72-c/outline_structure.jpg" height="72" width="72" /><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /><feedburner:origLink>http://www.ramkitech.com/2012/03/virtual-host-apache-httpd-server-tomcat.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-4180145408253964903</guid><pubDate>Fri, 24 Feb 2012 08:35:00 +0000</pubDate><atom:updated>2013-01-09T17:46:35.162+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">virtual hosting</category><category domain="http://www.blogger.com/atom/ns#">Tomcat</category><title>Understanding Virtual Host Concept in Tomcat</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
Hi in this post we will see how to setup virtual host in Apache Tomcat server. Virtual Host is in-built feature that allows to deploy multiple website(domains) in single instance of tomcat server.&amp;nbsp;The main benefit in this way is its cost effective.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #660000; font-size: large;"&gt;&lt;b&gt;Scenario:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
I am going to deploy 3 website with following domain names in single tomcat&lt;br /&gt;
&lt;span style="color: magenta;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: magenta;"&gt;http://www.ramki.com&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: magenta;"&gt;http://www.krishnan.com&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: magenta;"&gt;http://www.blog.ramki.com&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The following diagram is my outline.&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-50MAYcJxTgU/T0cX8gVvjFI/AAAAAAAAB80/EQgsZq9FtmM/s1600/virtual_host_tomcat_outline.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="440" src="http://3.bp.blogspot.com/-50MAYcJxTgU/T0cX8gVvjFI/AAAAAAAAB80/EQgsZq9FtmM/s640/virtual_host_tomcat_outline.jpg" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Outline structure of Virtual Host Concept in Tomcat&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
Here my tomcat IP address 192.168.1.15. or any IP address allocated my ISP. but it should be public IP address.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #660000; font-size: large;"&gt;&lt;b&gt;How all domain names are&amp;nbsp;pointing&amp;nbsp;to my Tomcat?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; When we purchase the domain name we need to update the our tomcat IP address to it.&amp;nbsp;like&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-95QlCfqRnZk/T0cgiGyyn4I/AAAAAAAAB9M/17OIGdre3WM/s1600/virtual_host_tomcat_dns_entries.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="152" src="http://4.bp.blogspot.com/-95QlCfqRnZk/T0cgiGyyn4I/AAAAAAAAB9M/17OIGdre3WM/s400/virtual_host_tomcat_dns_entries.jpg" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
or we can simulate same DNS Setup through hosts file in both Linux and Windows.&amp;nbsp;In Linux tha file is located at&lt;b style="background-color: #fff2cc;"&gt; /etc/hosts&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #660000; font-size: large;"&gt;&lt;b&gt;Now How Setup&amp;nbsp;Virtual Host Concept?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Before going to setup the virtual host. first take look at the&lt;b&gt; server.xml &lt;/b&gt;file in &lt;span style="background-color: #fff2cc;"&gt;conf &lt;/span&gt;folder in tomcat directory.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;server.xml&lt;/b&gt;&lt;br /&gt;
&lt;pre class="xml" name="code"&gt;&lt;server port="8005" shutdown="SHUTDOWN"&gt;
  
  &lt;service name="Catalina"&gt;
       
       &lt;engine defaulthost="localhost" name="Catalina"&gt;

            &lt;host appBase="webapps" autodeploy="true" name="localhost" unpackwars="true"&gt;
            &lt;/host&gt;

       &lt;/engine&gt;
   &lt;/service&gt;
&lt;/server&gt;

&lt;/pre&gt;
&lt;br /&gt;
here &lt;span style="background-color: #fff2cc;"&gt;&amp;lt;Engine&amp;gt;&lt;/span&gt; tag specified which engine is responsible for executing servlet. Here &lt;span style="background-color: #d9ead3;"&gt;&lt;b&gt;Catalina &lt;/b&gt;&lt;/span&gt;is the Engine.&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;&amp;lt;Host&amp;gt;&lt;/span&gt; tag &amp;nbsp;specify&amp;nbsp;the domain name and web apps base&amp;nbsp;location. here default domain name is localhost and web apps base&amp;nbsp;location&amp;nbsp;is webapps folder in tomcat directory.&amp;nbsp;here&amp;nbsp;&lt;b&gt;&lt;span style="color: #4c1130;"&gt;name&amp;nbsp;&lt;/span&gt;&lt;/b&gt;attribute to specify the domain name and&amp;nbsp;&lt;b&gt;&lt;span style="color: #4c1130;"&gt;appbase&amp;nbsp;&lt;/span&gt;&lt;/b&gt;attribute to specify the location of domain&amp;nbsp;specific&amp;nbsp;web apps folder path.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;Now we need to add more &amp;lt;Host&amp;gt; tags to represent to our domains&lt;br /&gt;
&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;span style="color: #cc0000;"&gt;&amp;lt;Host&lt;/span&gt;&lt;span style="color: purple;"&gt; name=&lt;/span&gt;&lt;span style="color: blue;"&gt;"www.ramki.com"&lt;/span&gt;&lt;span style="color: purple;"&gt;&amp;nbsp;appbase=&lt;/span&gt;&lt;span style="color: blue;"&gt;"ramki_webapps"&lt;/span&gt;&lt;span style="color: purple;"&gt; &lt;/span&gt;&lt;span style="color: #cc0000;"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;span style="color: #cc0000;"&gt;&amp;lt;Host&lt;/span&gt;&lt;span style="color: purple;"&gt; name=&lt;/span&gt;&lt;span style="color: blue;"&gt;"www.krishnan.com"&lt;/span&gt;&lt;span style="color: purple;"&gt;&amp;nbsp;appbase=&lt;/span&gt;&lt;span style="color: blue;"&gt;"krishnan_webapps"&lt;/span&gt;&lt;span style="color: #cc0000;"&gt; /&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;span style="color: #cc0000;"&gt;&amp;lt;Host&lt;/span&gt;&lt;span style="color: purple;"&gt; name=&lt;/span&gt;&lt;span style="color: blue;"&gt;"www.blog.ramki.com"&amp;nbsp;&lt;/span&gt;&lt;span style="color: purple;"&gt;appbase=&lt;/span&gt;&lt;span style="color: blue;"&gt;"blog_webapps"&lt;/span&gt;&lt;span style="color: #cc0000;"&gt; /&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #cc0000;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
Then we need to copy the webapps folder in tomcat and paste it anywhere and rename it to &lt;span style="background-color: #fff2cc;"&gt;ramki_webapps, krishnan_webapps, blog_webapps&lt;/span&gt; and update the path in &amp;lt;Host&amp;gt; tag&lt;br /&gt;
&lt;br /&gt;
&lt;!-- adsense --&gt;&lt;br /&gt;
&lt;br /&gt;
Modifies &lt;b&gt;server.xml&lt;/b&gt; file&lt;br /&gt;
&lt;pre class="xml" name="code"&gt;&lt;server port="8005" shutdown="SHUTDOWN"&gt;
  &lt;service name="Catalina"&gt;
  
      &lt;engine defaulthost="localhost" name="Catalina"&gt;
 
         &lt;host appbase="webapps" autodeploy="true" name="localhost" unpackwars="true"&gt;&lt;/host&gt;
         &lt;host appbase="ramki_webapps" autodeploy="true" name="www.ramki.com" unpackwars="true"&gt;&lt;/host&gt;
         &lt;host appbase="krishnan_webapps" autodeploy="true" name="www.krishnan.com" unpackwars="true"&gt;&lt;/host&gt;
         &lt;host appbase="blog_webapps" autodeploy="true" name="www.blog.ramki.com" unpackwars="true"&gt;&lt;/host&gt;
 
  
    &lt;/engine&gt;
  &lt;/service&gt;
&lt;/server&gt;

&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #660000;"&gt;Simulate the DNS&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
Open the&lt;b style="background-color: #fff2cc;"&gt; /etc/hosts&lt;/b&gt; file through root&amp;nbsp;privilege and add following entry&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #990000;"&gt;192.168.1.15 &amp;nbsp; &amp;nbsp; &amp;nbsp; www.ramki.com&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #990000;"&gt;192.168.1.15 &amp;nbsp; &amp;nbsp; &amp;nbsp; www.krishnan.com&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #990000;"&gt;192.168.1.15 &amp;nbsp; &amp;nbsp; &amp;nbsp; www.blog.ramki.com&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
deploy the websites to&amp;nbsp;respective&amp;nbsp;web apps folder and start the tomcat.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #660000; font-size: large;"&gt;Test:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
now open the browser and type&lt;span style="background-color: #fff2cc;"&gt; http://www.ramki.com &lt;/span&gt;then its shows the ramk website content. Other two sites&lt;span style="background-color: #fff2cc;"&gt; www.krishnan.com&lt;/span&gt; and &lt;span style="background-color: #fff2cc;"&gt;www.blog.ramki.com &lt;/span&gt;works respective webapps.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-V1tHM3N6s0o/T0cX-iGgqjI/AAAAAAAAB9A/h_q4r5vzulQ/s1600/virtual_host_tomcat_request_processing.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="360" src="http://2.bp.blogspot.com/-V1tHM3N6s0o/T0cX-iGgqjI/AAAAAAAAB9A/h_q4r5vzulQ/s640/virtual_host_tomcat_request_processing.jpg" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
In above diagram represent when we access&lt;span style="background-color: #fff2cc;"&gt; www.ramki.com&lt;/span&gt; the tomcat server consult with&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt; server.xml&lt;/b&gt;&lt;/span&gt; file and serves the files from&lt;span style="background-color: #fff2cc;"&gt; ramki_webapps&lt;/span&gt; directory.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #660000; font-size: large;"&gt;How is Virtual Host Works&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Here big question all websites are pointed to same tomcat. How tomcat can&amp;nbsp;distinguished&amp;nbsp;the request. (i.e) how tomcat knows browser requested ramki.com or www.krishnan.com&lt;br /&gt;
&lt;br /&gt;
The answer is based &lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;Host &lt;/b&gt;&lt;/span&gt;header field in HTTP request.&lt;br /&gt;
when we accssed www.ramki.com then browser make HTTP request. and the request look like this&lt;br /&gt;
&lt;br /&gt;
&lt;span style="-webkit-text-size-adjust: none; background-color: #fff2cc; font-family: Consolas, 'Lucida Console', monospace; font-size: 12px; white-space: pre-wrap;"&gt;&lt;b&gt;GET / HTTP/1.1&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="-webkit-text-size-adjust: none; background-color: #fff2cc; font-family: Consolas, 'Lucida Console', monospace; font-size: 12px; white-space: pre-wrap;"&gt;&lt;b&gt;Host: www.ramki.com&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="-webkit-text-size-adjust: none; background-color: #fff2cc; font-family: Consolas, 'Lucida Console', monospace; font-size: 12px; white-space: pre-wrap;"&gt;&lt;b&gt;Proxy-Connection: keep-alive&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="-webkit-text-size-adjust: none; background-color: #fff2cc; font-family: Consolas, 'Lucida Console', monospace; font-size: 12px; white-space: pre-wrap;"&gt;&lt;b&gt;User-Agent: Mozilla/5.0 (Windows NT 6.2) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="-webkit-text-size-adjust: none; background-color: #fff2cc; font-family: Consolas, 'Lucida Console', monospace; font-size: 12px; white-space: pre-wrap;"&gt;&lt;b&gt;Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="-webkit-text-size-adjust: none; background-color: #fff2cc; font-family: Consolas, 'Lucida Console', monospace; font-size: 12px; white-space: pre-wrap;"&gt;&lt;b&gt;Accept-Encoding: gzip,deflate,sdch&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="-webkit-text-size-adjust: none; background-color: #fff2cc; font-family: Consolas, 'Lucida Console', monospace; font-size: 12px; white-space: pre-wrap;"&gt;&lt;b&gt;Accept-Language: en-US,en;q=0.8&lt;/b&gt;&lt;/span&gt;&lt;span style="-webkit-text-size-adjust: none; background-color: white; font-family: Consolas, 'Lucida Console', monospace; font-size: 12px; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style="-webkit-text-size-adjust: none; background-color: #fff2cc; font-family: Consolas, 'Lucida Console', monospace; font-size: 12px; white-space: pre-wrap;"&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;span style="-webkit-text-size-adjust: none; white-space: pre-wrap;"&gt;h&lt;/span&gt;&lt;span style="-webkit-text-size-adjust: none; white-space: pre-wrap;"&gt;ere Host Field contain domain name&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b style="-webkit-text-size-adjust: none; background-color: #fff2cc; font-family: Consolas, 'Lucida Console', monospace; font-size: 12px; white-space: pre-wrap;"&gt;Host: www.ramki.com&lt;/b&gt; &lt;br /&gt;
&lt;br /&gt;
when tomcat receive the request from any browser, it read the Host field and understand which domain we requested, then consult the server.xml file and delegate to appropriate Host process thread&lt;br /&gt;
&lt;br /&gt;
check my&amp;nbsp;screen&amp;nbsp;cast for setup&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: blue; text-align: center;"&gt;Comments are welcomed&lt;/span&gt; &lt;br /&gt;
&lt;span style="color: blue; text-align: center;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #660000; font-size: large;"&gt;&lt;b&gt;screen-cast:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Consolas, 'Lucida Console', monospace;"&gt;&lt;span style="-webkit-text-size-adjust: none; font-size: 12px; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;iframe allowfullscreen="" frameborder="0" height="480" src="http://www.youtube.com/embed/V598VXQzTog?rel=0" width="853"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;div&gt;
&lt;style&gt;
.adslot-overlay {position: absolute; font-family: arial, sans-serif; background-color: rgba(0,0,0,0.65); border: 2px solid rgba(0,0,0,0.65); color: white !important; margin: 0; z-index: 2147483647; text-decoration: none; box-sizing: border-box; text-align: left;}.adslot-overlay-iframed {top: 0; left: 0; right: 0; bottom: 0;}.slotname {position: absolute; top: 0; left: 0; right: 0; font-size: 13px; font-weight: bold; padding: 3px 0 3px 6px; vertical-align: middle; background-color: rgba(0,0,0,0.45); text-overflow: ellipsis; white-space: nowrap; overflow: hidden;}.slotname span {text-align: left; text-decoration: none; text-transform: capitalize;}.revenue {position: absolute; bottom: 0; left: 0; right: 0; font-size: 11px; padding: 3px 0 3px 6px; vertial-align: middle; text-align: left; background-color: rgba(0,0,0,0.45); font-weight: bold; text-overflow: ellipsis; overflow: hidden; white-space: nowrap;}.revenue .name {color: #ccc;}.revenue .horizontal .metric {display: inline-block; padding-right: 1.5em;}.revenue .horizontal .name {padding-right: 0.5em;}.revenue .vertical .metric {display: block; line-height: 1.5em; margin-bottom: 0.5em;}.revenue .vertical .name, .revenue .vertical .value {display: block;}.revenue .square .metric, .revenue .button .metric {display: table-row;}.revenue .square .metric {line-height: 1.5em;}.revenue .square .name, .revenue .square .value, .revenue .button .value {display: table-cell;}.revenue .square .name {padding-right: 1.5em;}.revenue .button .name {display: block; margin-right: 0.5em; width: 1em; overflow: hidden; text-overflow: clip;}.revenue .button .name:first-letter {margin-right: 1.5em;}a.adslot-overlay:hover {border: 2px solid rgba(58,106,173,0.9);}a.adslot-overlay:hover .slotname {border-bottom: 1px solid rgba(81,132,210,0.9); background-color: rgba(58,106,173,0.9);}a.adslot-overlay:hover .revenue {border-top: 1px solid rgba(81,132,210,0.9); background-color: rgba(58,106,173,0.9);}div.adslot-overlay:hover {cursor: not-allowed; border: 2px solid rgba(64,64,64,0.9);}div.adslot-overlay:hover .slotname {border-bottom: 1px solid rgba(128,128,128,0.9); background-color: rgba(64,64,64,0.9);}div.adslot-overlay:hover .revenue {border-top: 1px solid rgba(128,128,128,0.9); background-color: rgba(64,64,64,0.9);}
&lt;/style&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=A-LDEmWzP9s:a2fq-iSE5_s:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=A-LDEmWzP9s:a2fq-iSE5_s:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=A-LDEmWzP9s:a2fq-iSE5_s:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?i=A-LDEmWzP9s:a2fq-iSE5_s:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=A-LDEmWzP9s:a2fq-iSE5_s:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ramki/feeds/~4/A-LDEmWzP9s" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ramki/feeds/~3/A-LDEmWzP9s/understanding-virtual-host-concept-in.html</link><author>noreply@blogger.com (Rama krishnnan E P)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-50MAYcJxTgU/T0cX8gVvjFI/AAAAAAAAB80/EQgsZq9FtmM/s72-c/virtual_host_tomcat_outline.jpg" height="72" width="72" /><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /><feedburner:origLink>http://www.ramkitech.com/2012/02/understanding-virtual-host-concept-in.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-2138008618074123921</guid><pubDate>Mon, 02 Jan 2012 10:27:00 +0000</pubDate><atom:updated>2013-05-10T10:10:21.147+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">grub</category><category domain="http://www.blogger.com/atom/ns#">Linux</category><category domain="http://www.blogger.com/atom/ns#">themes</category><category domain="http://www.blogger.com/atom/ns#">bootloader</category><title>Understanding the GRUB boot loader and Customize the themes</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
In this post we will discuss the&lt;span style="color: #cc0000;"&gt; GRUB2 (GRand Unified&amp;nbsp;Boot-loader)&lt;/span&gt; in&amp;nbsp;Linux. recently i surfing the&amp;nbsp;Linux&amp;nbsp;base concepts then i came to know about grub2. here i ll share what is&amp;nbsp;boot loader?, how grub2 boot loader is works? and how we can&amp;nbsp;customize? and how we apply the themes?&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #990000;"&gt;What is the&amp;nbsp;Boot Loader&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Boot loader is small code reside in &lt;a href="http://en.wikipedia.org/wiki/Master_boot_record" target="_blank"&gt;MBR &lt;/a&gt;to load the&amp;nbsp;kernel(core) of the operating system and give the control to OS. When PC is switched on the system controls goes to BIOS. Bios initialize the&amp;nbsp;peripherals&amp;nbsp;and check the booting order of the device then select the highest priority of the device execute the code stored in MBR of that device. Each&amp;nbsp;Operating&amp;nbsp;System shipped with&amp;nbsp;boot loader&lt;br /&gt;
&lt;br /&gt;
For Example :-&lt;br /&gt;
Microsoft&amp;nbsp;Windows&amp;nbsp;up to&amp;nbsp;Windows XP comes with &amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/NTLDR" target="_blank"&gt;NTLDR &lt;/a&gt;boot loader&lt;br /&gt;
From Windows Vista&amp;nbsp;onward&amp;nbsp;they use &lt;a href="http://en.wikipedia.org/wiki/Windows_Vista_startup_process" target="_blank"&gt;BOOTMGR &lt;/a&gt;as a&amp;nbsp;boot loader.&lt;br /&gt;
These&amp;nbsp;boot loaders&amp;nbsp;are&amp;nbsp;specifically&amp;nbsp;designed to load Windows OS. If want use these&amp;nbsp;boot loader&amp;nbsp;to boot other OS (Linux, Mac OS X) then we need to tweak using 3rd party tools like &lt;a href="http://neosmart.net/EasyBCD/" target="_blank"&gt;easyBCD&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
For Linux Operating System uses many&amp;nbsp;different&amp;nbsp;boot loaders as distro choice like &lt;a href="http://en.wikipedia.org/wiki/SYSLINUX" target="_blank"&gt;ISOLINUX&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/LILO_(boot_loader)" target="_blank"&gt;LILO&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/GNU_GRUB" target="_blank"&gt;GRUB&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Here we talk about GRUB2 boot loader.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #990000;"&gt;&lt;b&gt;What is Master Boot Record (MBR)?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Master Boot Record (MBR) is one block with 512 bytes. Its located in first sector of HDD, CD, other device. Its holds the partition entries and boot code.&lt;br /&gt;
Following MBR block, the actual partition are begin.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-NwYoKEwN4Hc/TwFo6L8SYZI/AAAAAAAAB6c/iOBGeBxnYsk/s1600/MBR.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="122" src="http://1.bp.blogspot.com/-NwYoKEwN4Hc/TwFo6L8SYZI/AAAAAAAAB6c/iOBGeBxnYsk/s400/MBR.jpg" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
This is helps if disconnect the HDD and connected to other machine, that machine understands ur partitions and file systems.&lt;br /&gt;
&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-VmKj_LMvAHo/TwFo7JyI9YI/AAAAAAAAB6o/Yuc0GkIgecE/s1600/mbr-detail.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="497" src="http://2.bp.blogspot.com/-VmKj_LMvAHo/TwFo7JyI9YI/AAAAAAAAB6o/Yuc0GkIgecE/s640/mbr-detail.jpg" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;HDD Layout and MBR&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
We know Total size of MBR is 512 bytes. In this &lt;span style="background-color: #fff2cc; color: purple;"&gt;446 bytes for Boot code&lt;/span&gt; (Boot loader code) and &lt;span style="color: purple;"&gt;4 Partition entry, each 16 bytes long&lt;/span&gt; (64 bytes) and 2 bytes MBR signature.&lt;br /&gt;
&lt;br /&gt;
Here this is&lt;span style="background-color: #fff2cc;"&gt;&amp;nbsp;limitation&amp;nbsp;that one hdd is maximum 4 primary partition or 3 primary&amp;nbsp;partition&amp;nbsp;and 1 logical&amp;nbsp;partition&lt;/span&gt;. The reason is MBR can store maximum 4 entry in partition table.&lt;br /&gt;
&lt;br /&gt;
If we use logical partition, its not actually&amp;nbsp; partition&amp;nbsp;&amp;nbsp;its another partition entry tables. its called &lt;span style="background-color: #fff2cc;"&gt;extended partition table&lt;/span&gt;, it&amp;nbsp;contain&amp;nbsp;many entries to logical volumes. (see the above diagram)&lt;br /&gt;
&lt;br /&gt;
Here each volume (or) partition has&amp;nbsp;separate&amp;nbsp;boot sector its called &lt;a href="http://en.wikipedia.org/wiki/Volume_boot_record" target="_blank"&gt;volume boot record&lt;/a&gt; apart from MBR. its used for&amp;nbsp;chain-loader of boot loader. The reason is grub boot loader can boot all&amp;nbsp;Linux&amp;nbsp;and some&amp;nbsp;Unix&amp;nbsp;also (freeBSD, netBSD, openBSD).&lt;br /&gt;
&lt;div style="text-align: center;"&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style="background-color: #ffe599; color: #990000;"&gt; &amp;nbsp; &amp;nbsp; GRUB Boot loader --&amp;gt; Load Linux Kernel&lt;/span&gt;&lt;/div&gt;
&lt;div style="text-align: center;"&gt;
&lt;span style="background-color: #ffe599; color: #990000;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
But it can't load the windows OS because GRUB don't know about Windows&amp;nbsp;start-up&amp;nbsp;process. Only Windows&amp;nbsp;Boot-loader&amp;nbsp;know about this. Windows Boot-loader stored in volume boot sector. First Grub is loaded and show the menu. Is user select the windows then GRUB load the volume boot sector code and give the control.&lt;br /&gt;
&lt;div style="text-align: center;"&gt;
&lt;span style="background-color: #ffe599;"&gt;&lt;span style="color: #990000;"&gt;GRUB Boot loader --&amp;gt; Windows Boot loader --&amp;gt; Load Windows Kernel&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
Here one limitation for some boot loaders&amp;nbsp;&amp;nbsp;like Windows boot-loader. They can't boot the OS, if OS is installed in logical partition.&amp;nbsp;that's&amp;nbsp;why windows OS we must install in primary partition. because that boot code can't capable to access the logical volume.&lt;br /&gt;
&lt;br /&gt;
The reason is if OS is installed primary partition then boot loaders easily can find the partition, because MBR contain primary partition entry.&lt;br /&gt;
&lt;br /&gt;
But when u installed in logical partition then that partition entry is residing&amp;nbsp;extended&amp;nbsp;partition table. Boot loader get overhead to&amp;nbsp;interpret&amp;nbsp;the&amp;nbsp;extended&amp;nbsp;&amp;nbsp; partition&amp;nbsp;table and get the entry then load the OS.&lt;br /&gt;
&lt;br /&gt;
&lt;!-- adsense --&gt;&lt;br /&gt;
&lt;span style="color: #990000;"&gt;&lt;b&gt;Why GRUB2?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;we already seen for&amp;nbsp;Linux&amp;nbsp;there are many boot loader.&amp;nbsp;now&amp;nbsp;let see why GRUB2 is more powerful than others.&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;GRUB2 is completely rewritten from original GRUB&lt;/li&gt;
&lt;li&gt;Its modular based, so we can load any module when its needed&lt;/li&gt;
&lt;li&gt;Its supports menu and themes&lt;/li&gt;
&lt;li&gt;GRUB2 acts as a mini OS, we can mount many&amp;nbsp;file-system&lt;/li&gt;
&lt;li&gt;Its capable to boot ISO&amp;nbsp;Linux&amp;nbsp;directly. &lt;a href="http://michael-prokop.at/blog/2009/05/25/boot-an-iso-via-grub2/" target="_blank"&gt;check here&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Its capable to load the OS&amp;nbsp;even though&amp;nbsp;its installed logical volume.&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
GRUB2 comes as a default boot loader in many&amp;nbsp;Linux&amp;nbsp;like Ubuntu 9&amp;nbsp;onward's.&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-i1sg-KVkx7A/TwFo3ImXF6I/AAAAAAAAB6I/KIsdWESzj9U/s1600/grub.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="302" src="http://3.bp.blogspot.com/-i1sg-KVkx7A/TwFo3ImXF6I/AAAAAAAAB6I/KIsdWESzj9U/s400/grub.jpg" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Normal GRUB Menu&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;span style="color: #990000;"&gt;&lt;b&gt;How GRUB2 Works?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; In 446 bytes in MBR is &lt;span style="background-color: #fff2cc;"&gt;not enough&lt;/span&gt; to put entire grub code. so MBR contain small code called&amp;nbsp;&lt;b&gt;&lt;span style="color: #cc0000;"&gt;boot.img&lt;/span&gt; &lt;/b&gt;and its capable to read first block of &lt;span style="color: #cc0000;"&gt;&lt;b&gt;core.img&lt;/b&gt;&lt;/span&gt; file from any partition (logical volume too) before partition is mounted. Because that time they cant understand the file system. so they read directly one sector (block) where core.img file is located.&lt;br /&gt;
&lt;br /&gt;
The first block of core.img is called &lt;b&gt;&lt;span style="color: #cc0000;"&gt;diskboot.img&lt;/span&gt;&lt;/b&gt; for HDD&amp;nbsp;or &lt;span style="color: #cc0000;"&gt;&lt;b&gt;cdboot.img&lt;/b&gt;&lt;/span&gt; for cd-rom or &lt;b&gt;&lt;span style="color: #cc0000;"&gt;pxeboot.img&lt;/span&gt;&lt;/b&gt; for network boot. This block contain many address of blocks , to iterate these address and load blocks then the complete&lt;b&gt;&lt;span style="color: #cc0000;"&gt; core.img &lt;/span&gt;&lt;/b&gt;(around 32 KB) comes into memory. This is job for boot code in GRUB.&lt;br /&gt;
&lt;br /&gt;
Actually &lt;b style="color: #cc0000;"&gt;core.img&lt;/b&gt; file is generated when GRUB is installed . This file contain one or more necessary module to mount the File system, where GRUB is installed. So&amp;nbsp;&lt;b style="color: #cc0000;"&gt;core.img&lt;/b&gt;&amp;nbsp;file is responsible for mount the File system and access the GRUB configuration file.&amp;nbsp;Once file system is mounted then we can&amp;nbsp;access&amp;nbsp;the files&amp;nbsp;normal&amp;nbsp;like&amp;nbsp;Linux. All other modules are located /boot/grub. Its loaded when its needed.&lt;br /&gt;
&lt;br /&gt;
All grub related configuration (menu entries, graphics resolution, timeout, etc...) are stored &lt;b&gt;&lt;span style="color: #cc0000;"&gt;grub.cfg&lt;/span&gt;&lt;/b&gt; file in &lt;span style="color: #cc0000;"&gt;/boot/grub/&lt;/span&gt; location. No need to put this line in MBR. because once File system is mounted then we can access through path &lt;span style="color: #990000;"&gt;&lt;b&gt;/boot/grub/grub.cfg&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #990000;"&gt;now we see 2&amp;nbsp;important&amp;nbsp;command for GRUB&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #cc0000;"&gt;sudo update-grub &amp;nbsp; &amp;nbsp;&lt;/span&gt;(or) &lt;span style="color: #cc0000;"&gt;sudo mk-config&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;this command generate the grub.cfg file dynamically. &lt;span style="background-color: #fff2cc;"&gt;Its &lt;b&gt;not update&lt;/b&gt;&lt;/span&gt; into MBR or volume boot record. Its just generate configuration file.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #cc0000;"&gt;sudo grup-install /dev/sda&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;this command &lt;span style="background-color: #fff2cc;"&gt;update the GRUB code in MBR&lt;/span&gt;. Its overwrite other boot loader code. (here sda is our HDD and dont mention any partition number)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #cc0000;"&gt;sudo grup-install /dev/sda5&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;this command update the GRUB code in Volume boot record. (here sda is our HDD and 5 is 5th partition)&lt;br /&gt;
&lt;br /&gt;
If u want to install GRUB in pendrive&lt;br /&gt;
first mount the pendrive and use grup-install command with --root-directory option&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #cc0000;"&gt;sudo grup-install --root-directory=/media/pendrive /dev/sdb&lt;/span&gt;&lt;/b&gt; &lt;br /&gt;
&amp;nbsp; &amp;nbsp;here /media/pendrive is mount point of pendrive and /dev/sdb is device file for pen drive , when want to know the device file run &lt;b&gt;&lt;span style="color: #cc0000;"&gt;sudo fdisk -l&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #990000;"&gt;&lt;b&gt;How grub.cfg file is generated?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; when i run the &lt;span style="color: #990000;"&gt;update-grub&lt;/span&gt; command then its generate the&lt;b&gt;&lt;span style="color: red;"&gt; grub.cfg&lt;/span&gt;&lt;/b&gt; file. But how?&lt;br /&gt;
&lt;br /&gt;
When install grub on our machine (its time of OS installation) they created some&amp;nbsp;supporting&amp;nbsp;files. they located in &lt;b&gt;&lt;span style="color: red;"&gt;/etc/default/grub &lt;/span&gt;&lt;/b&gt;file and&lt;b&gt;&lt;span style="color: red;"&gt; /etc/grub.d/ &lt;/span&gt;&lt;/b&gt;folder.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: red; font-weight: bold;"&gt;/etc/default/grub &lt;/span&gt;- contain environment variables of GRUB&lt;br /&gt;
&lt;b&gt;&lt;span style="color: red;"&gt;/etc/grub.d/&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span style="color: red; font-weight: bold;"&gt;&amp;nbsp;&lt;/span&gt;- contain some helper scripts files like theme,OS probe,custom scripts file&lt;br /&gt;
&lt;br /&gt;
When we run update-grub command then its called scripts files sequentially&amp;nbsp;accenting&amp;nbsp;number order. These scripts files read environment variables from&amp;nbsp;&amp;nbsp;&lt;b&gt;&lt;span style="color: red;"&gt;/etc/default/grub&amp;nbsp;&lt;/span&gt;&lt;/b&gt;file and generate the&amp;nbsp;&amp;nbsp;grub.cfg file&lt;br /&gt;
&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;&lt;span style="color: red;"&gt;grub.cfg&lt;/span&gt;&lt;/b&gt;&amp;nbsp;file is read only. so don't modify directly&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #990000;"&gt;&lt;b&gt;Customize&amp;nbsp;the GRUB menu&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;b&gt;&lt;span style="color: red;"&gt;grub.cfg&lt;/span&gt;&lt;/b&gt;&amp;nbsp;file is read only. so we need to modify the environment file or script file for customization.&lt;br /&gt;
&lt;br /&gt;
&lt;b style="background-color: #fff2cc;"&gt;Very important Note :&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;span style="background-color: #fff2cc;"&gt;&amp;nbsp; &amp;nbsp; If u modify the&amp;nbsp;&lt;span style="color: red; font-weight: bold;"&gt;/etc/default/grub file &lt;/span&gt;&lt;span style="font-weight: bold;"&gt;or&lt;/span&gt;&lt;span style="color: red; font-weight: bold;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: red; font-weight: bold;"&gt;/etc/grub.d/ &lt;/span&gt;scripts &amp;nbsp;then its not reflected in &lt;span style="color: red; font-weight: bold;"&gt;grub.cfg file.&lt;/span&gt;&amp;nbsp;So we must call the &lt;b&gt;update-grub&lt;/b&gt; command to reflect these changes into &lt;b&gt;grub.cfg.&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #660000;"&gt;1) Grub Time-Out&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;When we start the system, grub menu&amp;nbsp;appears&amp;nbsp;and wait for some time, is u not select the menu they load the default menu.&lt;br /&gt;
if u want to modify&amp;nbsp;the&amp;nbsp;time out&amp;nbsp;option&amp;nbsp;then change &lt;span style="color: blue;"&gt;GRUB_TIMEOUT=30&lt;/span&gt; in&amp;nbsp;&lt;b&gt;&lt;span style="color: red;"&gt;/etc/default/grub&amp;nbsp;&lt;/span&gt;&lt;/b&gt;file&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #660000;"&gt;2) Change Graphics Resolution&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #660000;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;Usually&amp;nbsp;graphics&amp;nbsp;menu appears in low graphics resolution like 640x480. If u know the resolution then change &lt;span style="color: blue;"&gt;GRUB_GFXMODE&lt;/span&gt; environment&amp;nbsp;variable&lt;br /&gt;
for ex: &amp;nbsp;&lt;span style="color: blue;"&gt;GRUB_GFXMODE&amp;nbsp;= 1024x768x32,640x480 &lt;/span&gt;here &lt;span style="color: blue;"&gt;width&amp;nbsp;&lt;/span&gt;x&amp;nbsp;&lt;span style="color: blue;"&gt;height &lt;/span&gt;x&lt;span style="color: blue;"&gt;&amp;nbsp;bit-depth&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #660000;"&gt;2) Change GRUB Background&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Grub menu appears in normal black background. If u want to change the image of the background then create &lt;span style="color: blue;"&gt;GRUB_BACKGROUND&lt;/span&gt; variable.&lt;br /&gt;
ex:&amp;nbsp;&lt;span style="color: blue;"&gt;GRUB_BACKGROUND=/home/ramki/Desktop/ram.jpg&lt;/span&gt;&lt;br /&gt;
Its accepts jpg,png,ttf format images&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-JRW86pi2hC8/TwFo4as703I/AAAAAAAAB6Q/DSB60d6Jhao/s1600/grub-background.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="476" src="http://3.bp.blogspot.com/-JRW86pi2hC8/TwFo4as703I/AAAAAAAAB6Q/DSB60d6Jhao/s640/grub-background.jpg" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;GRUB with background&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
If u want change the font colors and highlighting color.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #990000;"&gt;&lt;b&gt;Apply the Theme (see the video)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b style="color: #990000;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/b&gt;&amp;nbsp; Above&amp;nbsp;customization are just change the color and background. They not change the menu&amp;nbsp;position&amp;nbsp;and we can't add new&amp;nbsp;labels&amp;nbsp;and&amp;nbsp;progress&amp;nbsp;bar.&lt;br /&gt;
&lt;br /&gt;
We can build the theme with some components (boot_menu, progress_bar, image, vbox, hbox) arranged our own way position and size in theme definition file.&lt;br /&gt;
&lt;br /&gt;
each component have left,top,width,height properties. we can&amp;nbsp;mention&amp;nbsp;in pixel value or in percentage vale. Percentage is&amp;nbsp;recommended.&lt;br /&gt;
after theme is created then we need to specify in GRUB_THEME variable in /etc/default/grub file&lt;br /&gt;
&lt;br /&gt;
ex:&lt;br /&gt;
&lt;span style="color: blue;"&gt;GRUB_THEME = /boot/grub/theme/theme.txt&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #990000;"&gt;&lt;b&gt;This is screenshot of simple theme i used&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-JG4fHZFNFAU/TwFo5ZH6K2I/AAAAAAAAB6Y/pvICR_4erA0/s1600/grub-themes.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="478" src="http://2.bp.blogspot.com/-JG4fHZFNFAU/TwFo5ZH6K2I/AAAAAAAAB6Y/pvICR_4erA0/s640/grub-themes.jpg" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;After&amp;nbsp;Applying&amp;nbsp;Theme&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&amp;nbsp;Here we can use custom fonts also. but our fonts are not directly supported. we need to convert into pf2 format&amp;nbsp;then&amp;nbsp;we can use it.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #990000;"&gt;&lt;b&gt;sudo grup-mkfont --size=14 --range=0x0-0x7F --output=aerial.pf2 aerial.ttf&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
above line convert the aerial.ttf font to pf2 format with size is 14 and cover all character range.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;If u want the above theme, u can get it &lt;a href="http://ramki-projects.googlecode.com/files/theme.zip" target="_blank"&gt;from here &amp;nbsp;&lt;/a&gt;&amp;nbsp;&lt;/b&gt;then u modify the background image and other details&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #990000; font-size: large;"&gt;&lt;b&gt;Update 1 :&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #cc0000; font-family: Georgia, Times New Roman, serif;"&gt;&lt;b&gt;Why we need to install bootloader in Volume Boot Record (VBR)?&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; The reason is if MBR bootloader is not capable to boot Particular OS then that boot loader do the chain loading to load VBR boot loader and gives the control.&lt;br /&gt;
&lt;br /&gt;
for example there are 5 OS is there, but only one OS boot loader can sit in MBR. If that MBR bootloader is not capable to load other OS then how to load other OS. the answer is chain loading.&lt;br /&gt;
&lt;br /&gt;
so all 5 os install in different partition then bootloader is installed in VBR and MBR. but MBR is overrides based on which on recently installed. but VBR have one more copy of that OS specific boot loader. If MBR boot loader is capable to boot&amp;nbsp;another&amp;nbsp;OS then no need VBR boot loader. But If MBR&amp;nbsp;bootloader&amp;nbsp;is not capable to boot particular OS then MBR boot loader load the particular OS partition VBR and gives the control. now VBR boot loader can boot that OS.&lt;br /&gt;
&lt;br /&gt;
simple, 2 OS is there windows in sda2 partition and Linux in sda3 partition. and each partition contain their respective boot loader code in VBR. &amp;nbsp;so sda2 VBR contain windows boot loader.&lt;br /&gt;
&lt;br /&gt;
If GRUB bootloader is in MBR section, then it can load all Unix/Linux OS,but its can't load Windows OS. But windows boot loader is in sda2 VBR. so GRUB is load sda2 VBR to memory and gives control to it. Now Windows boot loader execute and load the Windows kernel.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #660000;"&gt;Screen cast (Watch in HD)&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;iframe allowfullscreen="" frameborder="0" height="480" src="http://www.youtube.com/embed/lCbQwrAQi8E" width="853"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #660000;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: blue;"&gt;comments are welcomed&lt;/span&gt;.&lt;br /&gt;
&lt;br /&gt;
This entire post is based on my understanding of GRUB. If anything wrong or i misunderstood please let me know.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #660000;"&gt;Resources:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div style="text-align: left;"&gt;
&lt;a href="http://en.wikipedia.org/wiki/GNU_GRUB"&gt;http://en.wikipedia.org/wiki/GNU_GRUB&lt;/a&gt; &lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;a href="https://help.ubuntu.com/community/Grub2"&gt;https://help.ubuntu.com/community/Grub2&lt;/a&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;a href="http://grub.gibibit.com/"&gt;http://grub.gibibit.com/&lt;/a&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;a href="http://www.dedoimedo.com/computers/grub-2.html"&gt;http://www.dedoimedo.com/computers/grub-2.html&lt;/a&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;a href="http://www.4shared.com/file/lFCl6wxL/grub_guidetar.html" target="_blank"&gt;The ThemingDefinitive Guide to &amp;nbsp;GRUB2&lt;/a&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=Kw86vv2_xCY:-kzUE1CAb9A:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=Kw86vv2_xCY:-kzUE1CAb9A:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=Kw86vv2_xCY:-kzUE1CAb9A:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?i=Kw86vv2_xCY:-kzUE1CAb9A:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=Kw86vv2_xCY:-kzUE1CAb9A:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ramki/feeds/~4/Kw86vv2_xCY" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ramki/feeds/~3/Kw86vv2_xCY/grub2-and-themes-customization.html</link><author>noreply@blogger.com (Rama krishnnan E P)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-NwYoKEwN4Hc/TwFo6L8SYZI/AAAAAAAAB6c/iOBGeBxnYsk/s72-c/MBR.jpg" height="72" width="72" /><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /><feedburner:origLink>http://www.ramkitech.com/2012/01/grub2-and-themes-customization.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-4178792325497526356</guid><pubDate>Wed, 07 Dec 2011 09:22:00 +0000</pubDate><atom:updated>2012-07-05T12:23:26.228+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">javaEE</category><category domain="http://www.blogger.com/atom/ns#">attack</category><category domain="http://www.blogger.com/atom/ns#">vulnerability</category><category domain="http://www.blogger.com/atom/ns#">security</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">sqlinjection</category><title>Beware of SQLInjection in Java Application</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;span class="Apple-style-span" style="font-family: arial, helvetica, sans-serif;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: arial, helvetica, sans-serif;"&gt;Hi In this post we will discuss what is &lt;a href="http://en.wikipedia.org/wiki/SQL_injection" target="_blank"&gt;SQL Injection&lt;/a&gt; attack. and how its may affect ur any &amp;nbsp;web application its use the backend database. Here i concentrate on java web application. &lt;a href="http://www.applicure.com/blog/owasp-top-10-2010" target="_blank"&gt;Open Web Application Security Project(OWAP)&lt;/a&gt; listed that SQL Injection is the top vulnerability attack for web application. Hacker's they Inject the SQL code in web request to the web application and take the control of backend database, even that backend database is not directly connected to internet. And we will see how to solve and prevent the SQL Injection in java Web Application.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: arial, helvetica, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: arial, helvetica, sans-serif;"&gt;For this purpose we need 1 tools. these tool are completely open source.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: arial, helvetica, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: arial, helvetica, sans-serif;"&gt;SQL Map - SqlMap is an open source penetration testing tool that automates the process of detecting and exploiting SQL Injection. we can get it from &lt;a href="http://sqlmap.sourceforge.net/" target="_blank"&gt;here&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #990000; font-family: arial, helvetica, sans-serif; font-size: large;"&gt;&lt;u&gt;SQLInjection&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: arial, helvetica, sans-serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; SQL injection is the technique to extract the database information through web application.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: arial, helvetica, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: red; font-family: arial, helvetica, sans-serif;"&gt;Scenario:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: arial, helvetica, sans-serif;"&gt;we have one database server [MySQL] and web application server [Tomcat]. consider that database server is not connected to internet. but its connected with application server. Now we will see using web application how to extract the information using sql-injection method.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: arial, helvetica, sans-serif;"&gt;Before see the&amp;nbsp;sql-injection,&amp;nbsp;we create small web application. It contain single jsp page like this&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: arial, helvetica, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: arial, helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: #ffd966; color: red;"&gt;&amp;nbsp;&amp;lt;form action="userCheck"&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: arial, helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: #ffd966; color: red;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;input type="text" name="user" value=""/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: arial, helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: #ffd966; color: red;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;input type="submit" value="Submit"/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: arial, helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: #ffd966; color: red;"&gt;&amp;nbsp; &amp;lt;/form&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: arial, helvetica, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: arial, helvetica, sans-serif;"&gt;&amp;nbsp;In userCheck Servlet receives the user input field and connect to databse server and fire the sql query based on user input and receive the ResultSet and iterate it print into the web page.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: arial, helvetica, sans-serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: arial, helvetica, sans-serif;"&gt;&lt;u&gt;userCheck servlet&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {

            String user = request.getParameter("user");
            Connection conn = null;
            String url = "jdbc:mysql://192.168.2.128:3306/";
            String dbName = "anvayaV2";
            String driver = "com.mysql.jdbc.Driver";
            String userName = "root";
            String password = "";
            try {
                Class.forName(driver).newInstance();
                conn = DriverManager.getConnection(url + dbName, userName, password);

                Statement st = conn.createStatement();
                String query = "SELECT * FROM  User where userId='" + user + "'";
                out.println("Query : " + query);
                System.out.printf(query);
                ResultSet res = st.executeQuery(query);

                out.println("

Results");
                while (res.next()) {
                    String s = res.getString("username");
                    out.println("

\t\t" + s);
                }
                conn.close();

            } catch (Exception e) {
                e.printStackTrace();
            }
        } finally {
            out.close();
        }
    &lt;/pre&gt;
When we execute the above code. In normal input execution look like follows&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-3aQo3YIE_Z0/Tt8e-A5v28I/AAAAAAAAB5Y/eH4GdqkSfZY/s1600/sample_application.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-3aQo3YIE_Z0/Tt8e-A5v28I/AAAAAAAAB5Y/eH4GdqkSfZY/s1600/sample_application.png" /&gt;&lt;/a&gt;&lt;/div&gt;
When we give the normal value like "ramki" then click the submit button then output like this&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-QxN3tQW-jHs/Tt8e_1h5-FI/AAAAAAAAB5o/Cn7BvX2GpjM/s1600/sample_application_output.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-QxN3tQW-jHs/Tt8e_1h5-FI/AAAAAAAAB5o/Cn7BvX2GpjM/s1600/sample_application_output.png" /&gt;&lt;/a&gt;&lt;/div&gt;
Its perfectly correct in normal behaviour. what happen when i put some special character or some sql statement in input box like this&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-UsUhr_FiXmA/Tt8fAwtT12I/AAAAAAAAB5w/FdDFzRYGHaU/s1600/sql_injection.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-UsUhr_FiXmA/Tt8fAwtT12I/AAAAAAAAB5w/FdDFzRYGHaU/s1600/sql_injection.png" /&gt;&lt;/a&gt;&lt;/div&gt;
when we click the submit button then it show all rows in my table like this&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-xf2dqqqqfZg/Tt8fBtSq1eI/AAAAAAAAB50/aB-YuDStquA/s1600/sql_injection_output.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-xf2dqqqqfZg/Tt8fBtSq1eI/AAAAAAAAB50/aB-YuDStquA/s1600/sql_injection_output.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Its big security breach in my application. what happen... Its one kind of sql injection&lt;br /&gt;
&lt;br /&gt;
lets see what happen&lt;br /&gt;
when i enter normal value in input box my servlet receives and substitute in the sql query and&amp;nbsp;execute&amp;nbsp;it.&lt;br /&gt;
&lt;br /&gt;
&lt;div style="text-align: center;"&gt;
&lt;span class="Apple-style-span" style="color: blue;"&gt;SELECT * FROM &amp;nbsp;User where userId='&lt;/span&gt; &lt;span class="Apple-style-span" style="color: purple;"&gt;ramki&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;'&lt;/span&gt;&lt;/div&gt;
its correct and we got correct output.&lt;br /&gt;
&lt;br /&gt;
what happen when i put &lt;span class="Apple-style-span" style="color: #cc0000;"&gt;sdfssd' or '1'='1&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;div style="text-align: center;"&gt;
&lt;span class="Apple-style-span" style="color: blue;"&gt;SELECT * FROM &amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;User&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;where&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;userId&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;='&lt;/span&gt;&amp;nbsp;&lt;span class="Apple-style-span" style="color: purple;"&gt;sdfssd' or '1'='1&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;'&lt;/span&gt;&lt;/div&gt;
its means&lt;br /&gt;
&lt;br /&gt;
&lt;div style="text-align: center;"&gt;
&lt;span class="Apple-style-span" style="color: blue;"&gt;SELECT * FROM &amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;User&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;where&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;userId&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;='&lt;/span&gt;&amp;nbsp;&lt;span class="Apple-style-span" style="color: purple;"&gt;sdfssd&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;' or '&lt;/span&gt;&lt;span class="Apple-style-span" style="color: purple;"&gt;1&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;'='&lt;/span&gt;&lt;span class="Apple-style-span" style="color: purple;"&gt;1&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;'&lt;/span&gt;&lt;/div&gt;
like this. so our query is altered. now new query have 2 condition. 2nd&amp;nbsp;condition&amp;nbsp;always true. 1st&amp;nbsp;condition&amp;nbsp;may be or may not be true. but these 2&amp;nbsp;condition&amp;nbsp;are connected with or logic. so where clause always true for all rows. the result is they bring all rows from our tables.&lt;br /&gt;
&lt;br /&gt;
This is called blind sql injection. If u want more details of sql injection the check here&lt;br /&gt;
&lt;a href="http://www.unixwiz.net/techtips/sql-injection.html"&gt;http://www.unixwiz.net/techtips/sql-injection.html&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://www.imperva.com/resources/glossary/sql_injection.html"&gt;http://www.imperva.com/resources/glossary/sql_injection.html&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://www.applicure.com/blog/owasp-top-10-2010"&gt;http://www.applicure.com/blog/owasp-top-10-2010&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Now we can enter the sql statement directly in input box&lt;br /&gt;
like&lt;span class="Apple-style-span" style="color: red;"&gt; ramki'&amp;nbsp;UNION SELECT * FROM mysql.`user` u --&lt;/span&gt;&lt;br /&gt;
then&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: blue; text-align: center;"&gt;SELECT * FROM &amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;User&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue; text-align: center;"&gt;where&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue; text-align: center;"&gt;userId&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue; text-align: center;"&gt;='&lt;/span&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;ramki'&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;UNI&lt;/span&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;ON SELECT * FROM mysql.`user` u --&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue; text-align: center;"&gt;'&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="text-align: center;"&gt;then its&amp;nbsp;&lt;/span&gt;means&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: blue; text-align: center;"&gt;SELECT * FROM &amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;User&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue; text-align: center;"&gt;where&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue; text-align: center;"&gt;userId&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue; text-align: center;"&gt;='&lt;/span&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;ramki&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;'&lt;/span&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;UNION SELECT * FROM mysql.`user` u --&lt;/span&gt;&lt;span class="Apple-style-span" style="color: magenta; text-align: center;"&gt;'&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
here they wont use * because its not&amp;nbsp;matched&amp;nbsp;with first table. so they find how many columns then use Union with second table.the user&amp;nbsp;particular&amp;nbsp;column they want . as result the get mysql database user information its exposed through our web application.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
sqlmap&lt;br /&gt;
It comes with a powerful detection engine, many niche features for the ultimate penetration tester and a broad range of switches lasting from database fingerprinting, over data fetching from the database&lt;br /&gt;
&lt;br /&gt;
Install the sqlmap in ur system or use &lt;a href="http://www.backtrack-linux.org/" target="_blank"&gt;BackTrack Linux&lt;/a&gt;&lt;br /&gt;
Here I used backtrack linux. because its already pre installed lots of applications like sqlmap.&lt;br /&gt;
In backtrack, sqlmap is located in /pentest/web/scanner/sqlmap&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;u&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;sqlmap commands&lt;/span&gt;&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: blue;"&gt;retrieve&amp;nbsp;all databases&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: purple;"&gt;./sqlmap.py -u&amp;nbsp;http://localhost:8080/SQLInject/userCheck?user=ramki&amp;nbsp; --dbs&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: blue;"&gt;retrieve&amp;nbsp;all tables&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: purple;"&gt;./sqlmap.py -u&amp;nbsp;http://localhost:8080/SQLInject/userCheck?user=ramki &amp;nbsp;-D test --tables&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: blue;"&gt;retrieve&amp;nbsp;all columns from particular table&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: purple;"&gt;./sqlmap.py -u&amp;nbsp;http://localhost:8080/SQLInject/userCheck?user=ramki &amp;nbsp;-D test -T User --columns&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: blue;"&gt;Dump all column valued &amp;nbsp;from particular table&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: purple;"&gt;./sqlmap.py -u&amp;nbsp;http://localhost:8080/SQLInject/userCheck?user=ramki &amp;nbsp;-D test -T User --dump&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="color: blue;"&gt;Dump some column valued &amp;nbsp;from particular table&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: purple;"&gt;./sqlmap.py -u&amp;nbsp;http://localhost:8080/SQLInject/userCheck?user=ramki &amp;nbsp;-D test -T User -C userId,password --dump&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
See the video for full demo (watch in HD)&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;iframe allowfullscreen="" frameborder="0" height="480" src="http://www.youtube.com/embed/C5PQ86nWMkM" width="853"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="color: #990000; font-size: large;"&gt;How To Prevent SQL Injection&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&amp;nbsp;Before&amp;nbsp;substitute&amp;nbsp;into query, we need to do the validation. for remove ir escaped the&amp;nbsp;special&amp;nbsp;character like single quote, key words like select, Union...&lt;/li&gt;
&lt;li&gt;Use Prepared&amp;nbsp;Statement&amp;nbsp;with placeholder&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="java" name="code"&gt;PreparedStatement  preparedStatement=conn.prepareStatement("SELECT * FROM  usercheck where username=?") ;
preparedStatement.setString(1, user);
&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
that setXXX() method do all the validation and escaping the special charcter&lt;br /&gt;
Now if use same blind sql injection like&amp;nbsp;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;sdfssd' or '1'='1&lt;/span&gt; then&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: blue; text-align: center;"&gt;SELECT * FROM &amp;nbsp;User where userId='&lt;/span&gt;&amp;nbsp;&lt;span class="Apple-style-span" style="color: purple;"&gt;sdfssd\' or \'1\'=\'1&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue; text-align: center;"&gt;'&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: blue; text-align: center;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="text-align: center;"&gt;here all special&amp;nbsp;character&amp;nbsp;are escaped&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="text-align: center;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="text-align: center;"&gt;When we use JPA kind of ORM tools like Hibernate, EclipseLink, TopLink that time also may be sqlinjection is possible.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="text-align: center;"&gt;Preventing the SQL injection we need to use NamedQuery instead of normal Query. Because NamedQuery internally used PreparedStement but normal query used norma Stement in java.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="text-align: center;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="text-align: center;"&gt;Normal Query in JPA&lt;/span&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;String q="SELECT r FROM  User r where r.userId='"+user+"'";
 Query query=em.createQuery(q);
 List users=query.getResultList();
&lt;/pre&gt;
&lt;span class="Apple-style-span" style="text-align: center;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="text-align: center;"&gt;so dont use normal query, use Named query like this &lt;/span&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;Query query=em.createNamedQuery("User.findByUserId");
 query.setParameter("userId", user);
 List users=query.getResultList();
&lt;/pre&gt;
&lt;pre class="java" name="code"&gt;&lt;/pre&gt;
&lt;pre class="java" name="code"&gt;&lt;/pre&gt;
&lt;div style="text-align: center;"&gt;
&lt;span class="Apple-style-span" style="color: blue;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;span class="Apple-style-span" style="color: blue; text-align: center;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large; text-align: center;"&gt;&lt;b&gt;U can download the demo code from&lt;span style="color: blue;"&gt;&amp;nbsp;&lt;a href="https://github.com/ramkicse/Sql-Injection-in-Java.git" target="_blank"&gt;GitHub&lt;/a&gt; &lt;/span&gt;(or)&lt;span style="color: blue;"&gt; &lt;a href="http://ramki-projects.googlecode.com/files/Sqlinjection.zip" target="_blank"&gt;Google code&lt;/a&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: blue; text-align: center;"&gt;Comments are welcomed&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=zYZcXjVMzok:vZ_btuPscDI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=zYZcXjVMzok:vZ_btuPscDI:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=zYZcXjVMzok:vZ_btuPscDI:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?i=zYZcXjVMzok:vZ_btuPscDI:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=zYZcXjVMzok:vZ_btuPscDI:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ramki/feeds/~4/zYZcXjVMzok" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ramki/feeds/~3/zYZcXjVMzok/beware-of-sqlinjection-in-java.html</link><author>noreply@blogger.com (Rama krishnnan E P)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-3aQo3YIE_Z0/Tt8e-A5v28I/AAAAAAAAB5Y/eH4GdqkSfZY/s72-c/sample_application.png" height="72" width="72" /><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /><feedburner:origLink>http://www.ramkitech.com/2011/12/beware-of-sqlinjection-in-java.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-3989018206833348694</guid><pubDate>Thu, 10 Nov 2011 04:11:00 +0000</pubDate><atom:updated>2012-07-05T12:21:23.062+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">iReport</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">JSF 2.0</category><category domain="http://www.blogger.com/atom/ns#">Java EE 6</category><category domain="http://www.blogger.com/atom/ns#">JasperReports</category><title>JSF + JPA + JasperReports (iReport) Part 1</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div style="text-align: left;"&gt;
Hi in this post we will see the overview of&amp;nbsp;&lt;a href="http://jasperforge.org/projects/jasperreports" target="_blank"&gt;JasperReports&amp;nbsp;&lt;/a&gt;and how to integrate into JSF application.&amp;nbsp;JasperReports is the world's most popular open source reporting engine. It is entirely written in Java and it is able to use data coming from any kind of data source and produce pixel-perfect documents that can be viewed, printed or exported in a variety of document formats including HTML, PDF, Excel, OpenOffice and Word.&lt;/div&gt;
&lt;br /&gt;
&amp;nbsp;In &lt;a href="http://www.primefaces.org/" target="_blank"&gt;Primeface&amp;nbsp;&lt;/a&gt;library&amp;nbsp;also use this&amp;nbsp;JasperReports&amp;nbsp;to generate the PDF, CSV and DOC formats with single line of code. &lt;a href="http://www.primefaces.org/showcase-labs/ui/exporter.jsf" target="_blank"&gt;see here&lt;/a&gt;. but its not flexible and we cant change template. so here we see the how to use&amp;nbsp;JasperReports&amp;nbsp;for create the template and&amp;nbsp;integrate &amp;nbsp;JSF 2.0.&lt;br /&gt;
&lt;br /&gt;
We are using &lt;a href="http://jasperforge.org/projects/ireport" target="_blank"&gt;iReport &lt;/a&gt;tool for crating template.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;Download JasperReports and iReport&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Jasper Reports download from &lt;a href="http://sourceforge.net/projects/jasperreports/files/jasperreports/JasperReports%204.1.3/jasperreports-4.1.3-project.zip/download" target="_blank"&gt;here&lt;/a&gt;. This zip contain jasper&amp;nbsp;library&amp;nbsp;and its dependencies and lots sample codes.&lt;/li&gt;
&lt;li&gt;iReport&amp;nbsp;download&amp;nbsp;&amp;nbsp;from &lt;a href="http://jasperforge.org/website/ireportwebsite/IR%20Website/ir_download.html?header=project&amp;amp;target=ireport" target="_blank"&gt;here&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
Now create the simple JSF Application to&amp;nbsp;retrieve&amp;nbsp;the data from database using JPA, then create the template using iReport and then integrate into&amp;nbsp;JSF application.&lt;/div&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: red; font-size: large;"&gt;&lt;b&gt;&lt;u&gt;JSF+JPA&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; Java Persistence API is standard way to access the all ORM (Object Relational&amp;nbsp;Mapping) tools like Hibernate, EclipseLink, TopLink,.. . These tools are&amp;nbsp;internally&amp;nbsp;use JDBC to access the database.&lt;br /&gt;
&lt;br /&gt;
the Heart of JPA is&amp;nbsp;&lt;u&gt;consist&amp;nbsp;of two parts&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span class="Apple-style-span" style="color: purple;"&gt;&lt;b&gt;persistence.xml&lt;/b&gt;&lt;/span&gt; - Its xml file describe the persistence provider (ORM&amp;nbsp;provider) and&amp;nbsp;connection&amp;nbsp;information like database URL, username and password. or&amp;nbsp;data source.&lt;/li&gt;
&lt;li&gt;&lt;span class="Apple-style-span" style="color: purple;"&gt;&lt;b&gt;Entity Classes&lt;/b&gt;&lt;/span&gt; - Its normal POJO class for each table in&amp;nbsp;underlying&amp;nbsp;table. This class is annotated with @Entity and some&amp;nbsp;annotation provided by JPA. Its way to express and map the property in the class into table in the DB.&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
These entity class are &amp;nbsp;manually&amp;nbsp;we can create or using IDE tools like&amp;nbsp;Net beans&amp;nbsp;IDE provide "&lt;b&gt;Entity Classes From Database&lt;/b&gt;" option to auto generate the Entity&amp;nbsp;Classes.&lt;b&gt;&lt;span class="Apple-style-span" style="color: #cc0000;"&gt; (See &lt;a href="http://www.youtube.com/watch?v=8JUiW10eqK0" target="_blank"&gt;video &lt;/a&gt;in below)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Once these entity&amp;nbsp;classes&amp;nbsp;are created then we need to create CRUD methods to wrapping these entities for ease of use. These kind of classes also auto generate from "&lt;b&gt;Session Beans from Entity Classes&lt;/b&gt;" option.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;Here we using &lt;b&gt;GlassFish Server 3&lt;/b&gt;. Its supports EJB 3.1.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
Now we create the JSF page to display the entity&amp;nbsp;classes&amp;nbsp;in table structure and provide buttons for export into variety of formats.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;u&gt;&lt;b&gt;&lt;i&gt;index.xhtml &lt;/i&gt;&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;pre class="xml" name="code"&gt;&lt;h:head&gt;
        &lt;title&gt;Facelet Title&lt;/title&gt;
    &lt;/h:head&gt;
    &lt;h:body&gt;
        
        &lt;h:form&gt;
            &lt;h:commandbutton actionlistener="#{demoBean.PDF}" value="PDF"&gt;
             &lt;h:commandbutton actionlistener="#{demoBean.DOCX}" value="Docx"&gt;
              &lt;h:commandbutton actionlistener="#{demoBean.XLSX}" value="Xlsx"&gt;
               &lt;h:commandbutton actionlistener="#{demoBean.ODT}" value="Odt"&gt;
               &lt;h:commandbutton actionlistener="#{demoBean.PPT}" value="Ppt"&gt;
        &lt;/h:commandbutton&gt;&lt;/h:commandbutton&gt;&lt;/h:commandbutton&gt;&lt;/h:commandbutton&gt;&lt;/h:commandbutton&gt;&lt;/h:form&gt;
        &lt;h:datatable border="1" value="#{demoBean.listOfUser}" var="user"&gt;
            &lt;h:column&gt;
                &lt;f:facet name="header"&gt;
                    User Name
                &lt;/f:facet&gt;
                #{user.userId}
            &lt;/h:column&gt;
            
            &lt;h:column&gt;
                &lt;f:facet name="header"&gt;
                    Password
                &lt;/f:facet&gt;
                #{user.password}
            &lt;/h:column&gt;
        &lt;/h:datatable&gt;
    &lt;/h:body&gt;

&lt;/pre&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class="Apple-style-span" style="color: #cc0000; font-size: large;"&gt;&lt;b&gt;&lt;u&gt;Jasper Reports&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
Once sample JSF application is completed then we going to integrate Jasper Reports.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
First, include all&amp;nbsp;necessary&amp;nbsp;lib into our application. We already download the jasper&amp;nbsp;library&amp;nbsp;zip file. Extract this file they have lots of folder. one for &lt;b&gt;dist &lt;/b&gt;folder contain main&lt;b&gt; jasperreports-4.1.3.jar&lt;/b&gt; file and &lt;b&gt;lib &lt;/b&gt;folder&amp;nbsp;contain&amp;nbsp;all&amp;nbsp;necessary&amp;nbsp;dependencies. see the&amp;nbsp;requirements&amp;nbsp;of jasper reports from &lt;a href="http://jasperforge.org/uploads/publish/jasperreportswebsite/trunk/requirements.html" target="_blank"&gt;here&lt;/a&gt;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;This is flow diagram of JasperReports.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-koz7AoOMRPQ/TsDnA35Qu6I/AAAAAAAAB5A/MezzxcoVxM4/s1600/jasperreport_overview.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="539" src="http://1.bp.blogspot.com/-koz7AoOMRPQ/TsDnA35Qu6I/AAAAAAAAB5A/MezzxcoVxM4/s640/jasperreport_overview.jpg" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Jasper Report Flow&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
Here we use iReport tool to generate the JRXML template. this file is pure xml file to describe the layout and&amp;nbsp;place-holders. then we need to compile into jasper file. its binary format. this compilation process we can do in 2 ways.&amp;nbsp;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;Using iReport to compile the jrxml file into jasper&lt;/li&gt;
&lt;li&gt;Using JasperReport API we can do through programme.&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
This is the code&amp;nbsp;snippet compile the jrxml file into jasper file&lt;br /&gt;
&lt;pre class="java" name="code"&gt;JasperCompileManager.compileReportToFile("report.jrxml", "report.jasper");
&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
or we can use iReport to compile&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-T4Vd3ApqbcE/TsI13WT9W6I/AAAAAAAAB5I/uvmi_41x-L8/s1600/jasper.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="512" src="http://3.bp.blogspot.com/-T4Vd3ApqbcE/TsI13WT9W6I/AAAAAAAAB5I/uvmi_41x-L8/s640/jasper.jpg" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
now compilation is finished. data is also ready. here data is java beans (entity beans) . This entity beans can't use directly. we wrap into one more class&amp;nbsp;&lt;b&gt;JRBeanCollectionDataSource &lt;/b&gt;then using &lt;b&gt;JasperFillManager &lt;/b&gt;we generate JRPRINT object.&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;code:&lt;/u&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;JRBeanCollectionDataSource beanCollectionDataSource=new JRBeanCollectionDataSource(listOfUser);
JasperPrint jasperPrint=JasperFillManager.fillReport("report.jasper", new HashMap(),beanCollectionDataSource);
&lt;/pre&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
once JasperPrint is ready then we export using &lt;b&gt;JasperExportManager&lt;/b&gt;&lt;/div&gt;
&lt;pre class="java" name="code"&gt;JasperExportManager.exportReportToPdfFile(jasperPrint, "report.pdf");
&lt;/pre&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
For exporting into &lt;span class="Apple-style-span" style="color: #cc0000;"&gt;&lt;i&gt;&lt;b&gt;docx, xlsx, odt, ods, pptx&lt;/b&gt;&lt;/i&gt;&lt;/span&gt; formats we should use &lt;span class="Apple-style-span" style="color: #cc0000;"&gt;&lt;i&gt;&lt;b&gt;JRDocxExporter,&amp;nbsp;JRXlsxExporter,&amp;nbsp;JROdtExporter,&amp;nbsp;JROdsExporter,&amp;nbsp;JRPptxExporter&amp;nbsp;&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
and one more thing we don't want to store the exported format into file system. we need to send these formats to client via stream.&lt;/div&gt;
&lt;u&gt;Code:&lt;/u&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;HttpServletResponse httpServletResponse=(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
httpServletResponse.addHeader("Content-disposition", "attachment; filename=report.docx");
ServletOutputStream servletOutputStream=httpServletResponse.getOutputStream();
JRDocxExporter docxExporter=new JRDocxExporter();
docxExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
docxExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, servletOutputStream);
docxExporter.exportReport();
FacesContext.getCurrentInstance().responseComplete();

&lt;/pre&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
here we get the OutputStream via FacesContext.&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;You can download this&amp;nbsp;complete&amp;nbsp;example from &lt;a href="https://github.com/ramkicse/JasperReports-1.git" target="_blank"&gt;GitHub&lt;/a&gt; (or)&lt;/span&gt;&amp;nbsp;&lt;a href="http://ramki-projects.googlecode.com/files/JasperReports.zip" target="_blank"&gt;Google Code&lt;/a&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;b&gt;&lt;u&gt;DemoBean.xml &lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ramki.jsf;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.export.oasis.JROdtExporter;
import net.sf.jasperreports.engine.export.ooxml.JRDocxExporter;
import net.sf.jasperreports.engine.export.ooxml.JRDocxExporterParameter;
import net.sf.jasperreports.engine.export.ooxml.JRPptxExporter;
import net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter;
import org.ramki.entity.User;
import org.ramki.session.UserFacade;

/**
 *
 * @author ramki
 */
@ManagedBean
@SessionScoped
public class DemoBean {
    private List&lt;user&gt; listOfUser;

    @EJB UserFacade userFacade;
    
    public List&lt;user&gt; getListOfUser() {
        listOfUser=userFacade.findAll();
        return listOfUser;
    }

    public void setListOfUser(List&lt;user&gt; listOfUser) {
        this.listOfUser = listOfUser;
    }
    JasperPrint jasperPrint;
    public void init() throws JRException{
        JRBeanCollectionDataSource beanCollectionDataSource=new JRBeanCollectionDataSource(listOfUser);
String  reportPath=  FacesContext.getCurrentInstance().getExternalContext().getRealPath("/reports/report.jasper");        jasperPrint=JasperFillManager.fillReport(reportPath, new HashMap(),beanCollectionDataSource);
    }
    
   public void PDF(ActionEvent actionEvent) throws JRException, IOException{
       init();
       HttpServletResponse httpServletResponse=(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
      httpServletResponse.addHeader("Content-disposition", "attachment; filename=report.pdf");
       ServletOutputStream servletOutputStream=httpServletResponse.getOutputStream();
       JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream);
       FacesContext.getCurrentInstance().responseComplete();
       
       
   }
    public void DOCX(ActionEvent actionEvent) throws JRException, IOException{
        init();
       HttpServletResponse httpServletResponse=(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
       httpServletResponse.addHeader("Content-disposition", "attachment; filename=report.docx");
       ServletOutputStream servletOutputStream=httpServletResponse.getOutputStream();
       JRDocxExporter docxExporter=new JRDocxExporter();
       docxExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
       docxExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, servletOutputStream);
       docxExporter.exportReport();
       FacesContext.getCurrentInstance().responseComplete();
   }
     public void XLSX(ActionEvent actionEvent) throws JRException, IOException{
        init();
       HttpServletResponse httpServletResponse=(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
      httpServletResponse.addHeader("Content-disposition", "attachment; filename=report.xlsx");
       ServletOutputStream servletOutputStream=httpServletResponse.getOutputStream();
       JRXlsxExporter docxExporter=new JRXlsxExporter();
       docxExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
       docxExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, servletOutputStream);
       docxExporter.exportReport();
       FacesContext.getCurrentInstance().responseComplete();
   }
      public void ODT(ActionEvent actionEvent) throws JRException, IOException{
       init();
       HttpServletResponse httpServletResponse=(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
      httpServletResponse.addHeader("Content-disposition", "attachment; filename=report.odt");
       ServletOutputStream servletOutputStream=httpServletResponse.getOutputStream();
       JROdtExporter docxExporter=new JROdtExporter();
       docxExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
       docxExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, servletOutputStream);
       docxExporter.exportReport();
       FacesContext.getCurrentInstance().responseComplete();
   }
       public void PPT(ActionEvent actionEvent) throws JRException, IOException{
       init();
       HttpServletResponse httpServletResponse=(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
      httpServletResponse.addHeader("Content-disposition", "attachment; filename=report.pptx");
       ServletOutputStream servletOutputStream=httpServletResponse.getOutputStream();
       JRPptxExporter docxExporter=new JRPptxExporter();
       docxExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
       docxExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, servletOutputStream);
       docxExporter.exportReport();
       FacesContext.getCurrentInstance().responseComplete();
   }
    
}

&lt;/user&gt;&lt;/user&gt;&lt;/user&gt;&lt;/pre&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style="color: #990000; font-size: large;"&gt;Update (02/01/2012):&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;table cellpadding="0" class="cf gJ" style="border-collapse: collapse; margin-top: 0px; text-align: left; width: auto;"&gt;&lt;/table&gt;
&lt;span style="color: #990000;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;i&gt;&lt;b&gt;mourad mourad&lt;/b&gt;&lt;/i&gt; mentioned that &lt;/span&gt;&lt;span style="color: purple;"&gt;report’s absolute path is hardcoded like C:\\UsersramkiDesktopreport.jasper". This&amp;nbsp;doesn't&amp;nbsp;work once you deploy your application in another application server.&lt;/span&gt;&lt;br /&gt;
&lt;table cellpadding="0" class="cf gJ" style="border-collapse: collapse; margin-top: 0px; text-align: left; width: auto;"&gt;&lt;/table&gt;
&lt;span style="color: #990000;"&gt;Yes&amp;nbsp;that's&amp;nbsp;correct. now i fix it.. i used for simplicity purpose.&lt;/span&gt;&lt;br /&gt;
&lt;table cellpadding="0" class="cf gJ" style="border-collapse: collapse; margin-top: 0px; text-align: left; width: auto;"&gt;&lt;/table&gt;
&lt;span style="color: #990000;"&gt;I try to used getResourceAsStream() method. But it wont work. the reason is our report needs some supporting files like images. If ur report contain no image then u can use getResourceAsStream() method.&lt;/span&gt;&lt;br /&gt;
&lt;table cellpadding="0" class="cf gJ" style="border-collapse: collapse; margin-top: 0px; text-align: left; width: auto;"&gt;&lt;/table&gt;
&lt;span style="color: #990000;"&gt;So here i want the path of the report jasper file. Then this report engine get the images from that path.&lt;/span&gt;&lt;br /&gt;
&lt;table cellpadding="0" class="cf gJ" style="border-collapse: collapse; font-family: arial, sans-serif; margin-top: 0px; text-align: left; width: auto;"&gt;&lt;tbody&gt;
&lt;tr class="acZ" style="height: 16px;"&gt;&lt;td class="gF gK" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-right: 8px; padding-top: 0px; text-align: left; vertical-align: top; white-space: nowrap; width: 478px;"&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;pre class="java" name="code"&gt;String  reportPath=  FacesContext.getCurrentInstance().getExternalContext().getRealPath("/reports/report.jasper");
jasperPrint=JasperFillManager.fillReport(reportPath, new HashMap(),beanCollectionDataSource); 

&lt;/pre&gt;
&lt;br /&gt;
&lt;span style="color: #990000; font-family: 'Times New Roman'; font-size: large; white-space: normal;"&gt;&lt;b&gt;Update (22/02/2012):&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: rgba(255, 255, 255, 0.917969);"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style="color: blue; font-family: arial, sans-serif;"&gt;&lt;b&gt;DrAhmedJava&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: arial, sans-serif;"&gt;commented&amp;nbsp;&lt;/span&gt;&lt;span style="background-color: rgba(255, 255, 255, 0.917969);"&gt;that &lt;/span&gt;&lt;span style="background-color: rgba(255, 255, 255, 0.917969); font-family: arial, sans-serif;"&gt;&lt;span style="color: purple;"&gt;i noticed that you have an exception - getOutputStream() has already been called for this response- in your output, and it also happened to me. and i want to share the solution:&lt;/span&gt;&lt;span style="color: #990000;"&gt; &lt;b&gt;(Thanks for sharing solution, i updated the code)&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: rgba(255, 255, 255, 0.917969); font-family: arial, sans-serif; white-space: normal;"&gt;&lt;span style="color: purple;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="color: #4c1130;"&gt;&lt;b&gt;The idea is that after the pdf() method writes the pdf to http response, the jsf servlet itself tries to reopen the response to write the html rendered from rendering stage of the life cycle, so the solution is to tell the jsf servlet that the response is complete and to skip the rest of life cycle&lt;span style="font-size: x-small;"&gt;:&lt;/span&gt;&lt;span style="font-size: 13px;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream); 
FacesContext.getCurrentInstance().responseComplete(); 
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #990000;"&gt;Update : &lt;/span&gt;&lt;/b&gt;&lt;span style="background-color: #fff2cc;"&gt;&lt;b&gt;For sub reports and Date Objects check&lt;a href="http://www.ramkitech.com/2012/06/jsf-jpa-jasperreports-ireport-part-2.html" target="_blank"&gt; Part 2 of this&amp;nbsp;Series&amp;nbsp;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;span class="Apple-style-span" style="color: magenta; font-size: large;"&gt;&lt;b&gt;&lt;i&gt;Watch the video in HD&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;iframe allowfullscreen="" frameborder="0" height="480" src="http://www.youtube.com/embed/8JUiW10eqK0?rel=0&amp;amp;hd=1" width="853"&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span class="Apple-style-span" style="color: red; font-size: large;"&gt;Comments are Welcomed&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=L5_PJpCKhk8:vAJpj_ApuGE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=L5_PJpCKhk8:vAJpj_ApuGE:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=L5_PJpCKhk8:vAJpj_ApuGE:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?i=L5_PJpCKhk8:vAJpj_ApuGE:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=L5_PJpCKhk8:vAJpj_ApuGE:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ramki/feeds/~4/L5_PJpCKhk8" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ramki/feeds/~3/L5_PJpCKhk8/jsf-jpa-jasperreports-ireport.html</link><author>noreply@blogger.com (Rama krishnnan E P)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-koz7AoOMRPQ/TsDnA35Qu6I/AAAAAAAAB5A/MezzxcoVxM4/s72-c/jasperreport_overview.jpg" height="72" width="72" /><georss:featurename>Paud Rd, Kothrud, Pune, Maharashtra, India</georss:featurename><georss:point>18.47960905583197 73.740234375</georss:point><georss:box>10.730568055831968 63.632812375 26.22865005583197 83.847656375</georss:box><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /><feedburner:origLink>http://www.ramkitech.com/2011/11/jsf-jpa-jasperreports-ireport.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-8840303299955143894</guid><pubDate>Mon, 18 Jul 2011 11:56:00 +0000</pubDate><atom:updated>2011-07-22T13:52:11.036+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">javaSE</category><category domain="http://www.blogger.com/atom/ns#">javaSE7</category><title>Learn Java 7</title><description>&lt;span class="Apple-style-span" style="font-family: sans-serif; line-height: 19px;"&gt;Java 7 &amp;nbsp;is an upcoming major update to Java, releasing on July 28, its upgrade/add many features.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: sans-serif; line-height: 19px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: sans-serif; line-height: 19px;"&gt;&lt;span class="Apple-style-span" style="color: magenta;"&gt;Upgraded Features&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
- Java 7 &lt;span class="Apple-style-span" style="background-color: yellow;"&gt;update the XML and&amp;nbsp;Web Service&amp;nbsp;stack &lt;/span&gt;to current stable build &lt;a href="http://jaxp.java.net/"&gt;JAXP&lt;/a&gt; 1.4, &lt;a href="http://www.oracle.com/technetwork/articles/javase/index-140168.html"&gt;JAXB&lt;/a&gt; 2.2 and &lt;a href="http://jax-ws.java.net/"&gt;JAX-WS&lt;/a&gt; 2.2.&lt;br /&gt;
- Update the &lt;span class="Apple-style-span" style="background-color: yellow;"&gt;&lt;a href="http://download.oracle.com/javase/6/docs/technotes/guides/jweb/otherFeatures/nimbus_laf.html"&gt;Nimbus&lt;/a&gt; Look and Feel&lt;/span&gt; (Next Cross Platform UI). Its already added Java 6 Update 10. check &lt;a href="http://download.oracle.com/javase/6/docs/technotes/guides/jweb/otherFeatures/nimbus_laf.html"&gt;here&lt;/a&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://java.sun.com/developer/technicalArticles/javase/java6u10/images/nimbus.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="195" src="http://java.sun.com/developer/technicalArticles/javase/java6u10/images/nimbus.gif" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;
&lt;/div&gt;- &lt;span class="Apple-style-span" style="background-color: yellow;"&gt;Translucent and shaped Windows&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;This feature is also included in java 6 update 10. &amp;nbsp;this features provide to create transparent and any shape window in java. for more info &lt;a href="http://www.pushing-pixels.org/2008/03/18/more-tricks-with-translucent-swing-windows.html"&gt;check this&lt;/a&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://www.pushing-pixels.org/wp-content/uploads/2008/03/window-soft-clipped-translucent.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://www.pushing-pixels.org/wp-content/uploads/2008/03/window-soft-clipped-translucent.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: magenta; font-size: large;"&gt;New features in java 7&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: purple; font-size: large;"&gt;Small languages changes (Project Coin Part 1)&lt;/span&gt;&lt;br /&gt;
&lt;a href="http://blogs.oracle.com/darcy/entry/project_coin_jsr_334_pr"&gt;Project Coin&lt;/a&gt;&amp;nbsp;is one of the &amp;nbsp;project in java 7 for java language spec (JLS). Project Coin have 2 parts. the first part is add to java 7. and next part is comes with java 8 in next year (2012).&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&amp;nbsp;Binary literals and underscore in numeric literals&lt;/li&gt;
&lt;/ul&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;now we can assign binary values directly.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;int currency=19_00_000;
int binary=0b100000;
    
System.out.println(binary);
System.out.println(currency);
&lt;/pre&gt;the output of above code snippets is 32 and 1900000&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Strings in switch statements&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
now we can use string literals in switch statements.&lt;br /&gt;
&lt;pre class="java" name="code"&gt;public static void main(String[] args) {
       String data="java 7";
       
       switch(data)
       {
           case "java":
           case "JAVA":
               System.out.println("Java");
               break;
           case "java 7":
           case "JAVA 7":
               System.out.println("Java 7");
                break;
            default:
                   System.out.println("Otherthan java");
              
       }
        
}
&lt;/pre&gt;it prints "Java 7".&lt;br /&gt;
&lt;br /&gt;
&lt;!-- adsense --&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&amp;nbsp;Multi-catch statements and good re throw. &lt;a href="http://www.baptiste-wicht.com/2010/05/better-exception-handling-in-java-7-multicatch-and-final-rethrow/"&gt;Check Here&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;try with resource stements. check &lt;a href="http://java.dzone.com/articles/java-7-new-try-resources?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed:+javalobby/frontpage+(Javalobby+/+Java+Zone)"&gt;here&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;new&amp;nbsp;diamond &amp;lt;&amp;gt;&amp;nbsp;operator. check &lt;a href="http://marxsoftware.blogspot.com/2011/03/jdk-7-diamond-operator.html"&gt;here&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
some other features of project coin will come with Java 8 in next year.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: purple; font-size: large;"&gt;NIO 2 (New I/O 2)&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; This one of the biggest update in java 7. It fill the gap between &amp;nbsp;underlaying OS and Java in terms of file manipulation. Oracle provide good tutorial about NIO 2 &lt;a href="http://download.oracle.com/javase/tutorial/essential/io/fileio.html"&gt;here&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: purple; font-size: large;"&gt;JLayer&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;code style="font-size: 1.2em;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/code&gt;&lt;code&gt;JLayer&lt;/code&gt;&amp;nbsp;is a universal decorator for Swing components which enables you to implement various advanced painting effects as well as receive notifications of all&amp;nbsp;&lt;code&gt;AWTEvent&lt;/code&gt;s generated within its borders.&amp;nbsp;&lt;/span&gt;check&lt;a href="http://download.oracle.com/javase/tutorial/uiswing/misc/jlayer.html"&gt; this tutorial&lt;/a&gt;&amp;nbsp;about how to decorate JLayer in existing swing component.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: purple; font-size: large;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; line-height: 21px;"&gt;Support for dynamically-typed languages (&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: purple; font-size: large;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; line-height: 21px;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; cursor: auto; display: inline; font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; cursor: auto; display: inline; font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;InvokeDynamic&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; line-height: 21px;"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;This feature is not for normal developers. Its only for those are porting his language into JVM. Check &lt;a href="http://en.wikipedia.org/wiki/List_of_JVM_languages"&gt;here&lt;/a&gt; for list of languages supported by JVM.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: purple; font-size: large;"&gt;other features&lt;/span&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21px;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span class=" aptureTMMSelection" style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;Upgrade class-loader architecture&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21px;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span class=" aptureTMMSelection" style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;Support Uncode 6.0&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21px;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span class=" aptureTMMSelection" style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span class="Apple-style-span" style="border-collapse: separate;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span class=" aptureTMMSelection" style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;Elliptic-curve cryptography (ECC)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21px;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span class=" aptureTMMSelection" style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span class="Apple-style-span" style="border-collapse: separate;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span class=" aptureTMMSelection" style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span class="Apple-style-span" style="border-collapse: separate;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span class=" aptureTMMSelection" style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;JDBC 4.1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21px;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span class=" aptureTMMSelection" style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span class="Apple-style-span" style="border-collapse: separate;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span class=" aptureTMMSelection" style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span class="Apple-style-span" style="border-collapse: separate;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span class=" aptureTMMSelection" style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;&lt;span style="background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;"&gt;XRender Pipeline for mordern GPU&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
The Next Java 8 will give support for Modular JVM and modular programming (Project Jigsaw), Project Coin part 2, Project Lamda, collection literals and very importantly oracle going to merge JRockit into Hotspot VM.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
comments are welcomed,&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=C15zeg2MPH0:y7ptH3Q4tdg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=C15zeg2MPH0:y7ptH3Q4tdg:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=C15zeg2MPH0:y7ptH3Q4tdg:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?i=C15zeg2MPH0:y7ptH3Q4tdg:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=C15zeg2MPH0:y7ptH3Q4tdg:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ramki/feeds/~4/C15zeg2MPH0" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ramki/feeds/~3/C15zeg2MPH0/learn-java-7.html</link><author>noreply@blogger.com (Rama krishnnan E P)</author><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /><feedburner:origLink>http://www.ramkitech.com/2011/07/learn-java-7.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-663118231264977643</guid><pubDate>Mon, 11 Jul 2011 13:54:00 +0000</pubDate><atom:updated>2013-03-04T17:25:51.718+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">multiple_instances</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">Tomcat</category><title>Running Multiple Tomcat Instances on Single Machine</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
In this post we will see how to run&amp;nbsp;multiple&amp;nbsp;tomcat instances on single machine and under single user account.&lt;br /&gt;
We first see the &amp;nbsp;tomcat directory structure. .&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-vrVNkx2Hbsc/ThsBrNEDQWI/AAAAAAAAB1w/yAuv8T8DoDU/s1600/tomcat_structure.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="125" src="http://4.bp.blogspot.com/-vrVNkx2Hbsc/ThsBrNEDQWI/AAAAAAAAB1w/yAuv8T8DoDU/s400/tomcat_structure.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
here each folder uses&amp;nbsp;following&amp;nbsp;purpose.&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;b&gt;bin&lt;/b&gt; - &amp;nbsp;It contains all binary and script files for running tomcat.&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;b&gt;lib&lt;/b&gt; - contains all shared&amp;nbsp;libraries&amp;nbsp;used for tomcat&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;b&gt;conf&lt;/b&gt; -&amp;nbsp;contains&amp;nbsp;configuration information like which port tomcat can bind , etc...&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;b&gt;logs&lt;/b&gt; - it contain all logging details&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;b&gt;temp&lt;/b&gt; - this folder tomcat used for&amp;nbsp;temporary&amp;nbsp;files purpose&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;b&gt;webapps&lt;/b&gt; - this folder is very important. here we put all application war files.&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;b&gt;work&lt;/b&gt; - If application contain any jsp then jsp is translated and&amp;nbsp;converted&amp;nbsp;into servlet its stores here.&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
In when run the tomcat its uses 5 environment variables. They are&amp;nbsp;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
CATALINA_HOME, CATALINA_BASE,&amp;nbsp;CATALINA_TMPDIR,&amp;nbsp;JRE_HOME/JAVA_HOME,&amp;nbsp;CLASSPATH&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
in above list&amp;nbsp;CATALINA_HOME and JAVA_HOME is mandatory environment variables. all others are optional and its can be calculated using&amp;nbsp;CATALINA_HOME.&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;b&gt;CATALINA_HOME&lt;/b&gt; - this environment variable should point to tomcat base folder, where tomcat binary are &amp;nbsp;installed/extracted. so based on CATALINA_HOME we can get &lt;b&gt;bin&lt;/b&gt; and &lt;b&gt;lib&lt;/b&gt; folder&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;b&gt;CATALINA_BASE&lt;/b&gt; - If we not specified then&amp;nbsp;CATALINA_HOME value is set. This variable pointed to configuration and webapps folder. Based on this variable server uses &lt;b&gt;conf, logs, temp, webapps, work&lt;/b&gt; folders.&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
Usual ways to run the tomcat is only set CATALINA_HOME environment variable. and run the &lt;b&gt;startup.sh&lt;/b&gt; script file. this startup.sh file automatically calculate and&amp;nbsp;assign&amp;nbsp;the&amp;nbsp;values&amp;nbsp;of other variables what we are not set.&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-zn1ijTFg4LI/Thwmpa5MxKI/AAAAAAAAB10/licoYKPUL_k/s1600/startup_tomcat.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="85" src="http://2.bp.blogspot.com/-zn1ijTFg4LI/Thwmpa5MxKI/AAAAAAAAB10/licoYKPUL_k/s400/startup_tomcat.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
startup.sh file set the environment variable and &amp;nbsp;then call catalina.sh file. this files is read CATALINA_BASE value and attach conf i.e $CATALINA_BASE/conf folder and get server.xml. this file is heart of tomcat. it contains all configuration information. like which tomcat uses as shoutdown port, connector post, host name, application folder ,.. for example usually tomcat uses 8080 is a connector port, so we can access http://localhost:8080/&amp;nbsp;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
if we set the $CATALINA_BASE explicitly then tomcat uses our variable to search and get the server.xml file from our target place, what we specified in&amp;nbsp;CATALINA_BASE.&amp;nbsp;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
this is trick to run multiple tomcat in single machine. we don't change&amp;nbsp;CATALINA_HOME value. we need to change&amp;nbsp;CATALINA_BASE value before start/shutdown the tomcat.&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
create one folder named "&lt;b&gt;tomcat-instance1&lt;/b&gt;" anywhere, and copy&lt;b&gt; conf, temp, webapps&lt;/b&gt; &amp;nbsp;folder from&amp;nbsp;CATALINA_HOME folder and change conf/server.xml file in&amp;nbsp;&lt;b&gt;tomcat-instance1&lt;/b&gt;. we need to change 3 port shutdown port, connector port and ajp port.&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;b&gt;shutdown port&lt;/b&gt; - this port is used for shutdown the tomcat. when we call the shutdown.sh script they send&amp;nbsp;signal&amp;nbsp;to shutdown port. this port listen by tomcat java process. if&amp;nbsp;signal&amp;nbsp;is received the that process then its cleanup and exit by itself.&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;b&gt;connector Port &lt;/b&gt;-This port is actual port to expose the application to outside client.&amp;nbsp;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;b&gt;ajp port&lt;/b&gt; - this port is used to apache httpd server &amp;nbsp;communicate to tomcat. this port used when we setup load balanced server.&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
see the sample server.xml file&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;server port="8005" shutdown="SHUTDOWN"&gt;&lt;/server&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
.... ..&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
&lt;/div&gt;
&lt;pre class="xml" name="code"&gt;&lt;server port="8005" shutdown="SHUTDOWN"&gt;
.....
 &lt;connector connectiontimeout="20000" port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol" redirectport="8443"&gt;

&lt;connector port="8009" protocol="AJP/1.3" redirectport="8443"&gt;
&lt;/connector&gt;&lt;/connector&gt;&lt;/server&gt;&lt;/pre&gt;
&lt;div class="separator" style="clear: both; text-align: left;"&gt;
so we change these three port to different number, because once this port is binded &amp;nbsp;then other process can't bind it again. so wee bind different port. so tomcat-instance1/conf/server.xml file i configured server port =8105, connector port = 8181, ajp port = 8109.&lt;/div&gt;
&lt;pre class="xml" name="code"&gt;&lt;server port="8105" shutdown="SHUTDOWN"&gt;
.....
 &lt;connector connectiontimeout="20000" port="8181" protocol="org.apache.coyote.http11.Http11NioProtocol" redirectport="8443"&gt;
&lt;connector port="8109" protocol="AJP/1.3" redirectport="8443"&gt;
&lt;/connector&gt;&lt;/connector&gt;&lt;/server&gt;&lt;/pre&gt;
&lt;br /&gt;
now we can create two script file for startup and shutdown the tomcat-instance1.&lt;br /&gt;
&lt;u&gt;startup-instance1.sh&lt;/u&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: purple; font-family: Georgia, 'Times New Roman', serif;"&gt;export CATALINA_BASE= /home/ramki/tomcat-instance1&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: purple; font-family: Georgia, 'Times New Roman', serif;"&gt;cd $CATALINA_HOME/bin&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: purple; font-family: Georgia, 'Times New Roman', serif;"&gt;./startup.sh&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: purple; font-family: Georgia, 'Times New Roman', serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: purple; font-family: Georgia, 'Times New Roman', serif;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: purple; font-family: Georgia, 'Times New Roman', serif;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style="color: black; font-family: 'Times New Roman'; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;
&lt;span class="Apple-style-span" style="color: purple; font-family: Georgia, 'Times New Roman', serif;"&gt;&lt;u&gt;shutdown-instance1.sh&lt;/u&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="color: black; font-family: 'Times New Roman'; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;
&lt;span class="Apple-style-span" style="color: purple; font-family: Georgia, 'Times New Roman', serif;"&gt;&lt;span class="Apple-style-span" style="color: purple; font-family: Georgia, 'Times New Roman', serif;"&gt;export CATALINA_BASE= /home/ramki/tomcat-instance1&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="color: black; font-family: 'Times New Roman'; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;
&lt;span class="Apple-style-span" style="color: purple; font-family: Georgia, 'Times New Roman', serif;"&gt;&lt;span class="Apple-style-span" style="color: purple; font-family: Georgia, 'Times New Roman', serif;"&gt;cd $CATALINA_HOME/bin&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="color: black; font-family: 'Times New Roman'; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;
&lt;span class="Apple-style-span" style="color: purple; font-family: Georgia, 'Times New Roman', serif;"&gt;&lt;span class="Apple-style-span" style="color: purple; font-family: Georgia, 'Times New Roman', serif;"&gt;./shutdown.sh&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Georgia, 'Times New Roman', serif;"&gt;here we explicitly set the&amp;nbsp;&lt;/span&gt;CATALINA_BASE variable and point to new tomcat-instance1&lt;br /&gt;
the we go to&amp;nbsp;CATALINA_HOME/bin folder because all binary for running tomcat is still present in&amp;nbsp;CATALINA_HOME folder then startup/shutdown the script.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-BSsNs8Ze5eI/Thw7w1m9DSI/AAAAAAAAB18/-bHb7I6TkQo/s1600/tomcat1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="72" src="http://4.bp.blogspot.com/-BSsNs8Ze5eI/Thw7w1m9DSI/AAAAAAAAB18/-bHb7I6TkQo/s400/tomcat1.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
Based on above technique we can create many instance folder and change conf/server.xml file port values and run that instance with own newly created script files.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #660000; font-size: large;"&gt;&lt;b&gt;Update 1:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;Java Experience&amp;nbsp;created&amp;nbsp;a small&amp;nbsp;utility&amp;nbsp;for automatically generate the multiple tomcat instances in Windows/Linux Systems. &lt;a href="http://www.javaexperience.com/run-multiple-tomcat-instances/" target="_blank"&gt;Check Here&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="color: #990000;"&gt;see the latest post&amp;nbsp;:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;a href="http://www.ramkitech.com/2012/02/understanding-virtual-host-concept-in.html" target="_blank"&gt;Understanding Virtual Host in Tomcat&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
see the screen cast for running mutiple instance of tomcat&lt;br /&gt;
&lt;br /&gt;
&lt;iframe allowfullscreen="" frameborder="0" height="349" src="http://www.youtube.com/embed/n9l8WHHp_30?rel=0&amp;amp;hd=1" width="560"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
comments are welcomed&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=VjqA7d5ilYA:UswK68_Pub0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=VjqA7d5ilYA:UswK68_Pub0:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=VjqA7d5ilYA:UswK68_Pub0:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?i=VjqA7d5ilYA:UswK68_Pub0:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=VjqA7d5ilYA:UswK68_Pub0:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ramki/feeds/~4/VjqA7d5ilYA" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ramki/feeds/~3/VjqA7d5ilYA/running-multiple-tomcat-instances-on.html</link><author>noreply@blogger.com (Rama krishnnan E P)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-vrVNkx2Hbsc/ThsBrNEDQWI/AAAAAAAAB1w/yAuv8T8DoDU/s72-c/tomcat_structure.png" height="72" width="72" /><georss:featurename>Unknown location.</georss:featurename><georss:point>18.521283325496277 73.8720703125</georss:point><georss:box>14.640897325496278 68.81835931250001 22.40166932549628 78.92578131249999</georss:box><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /><feedburner:origLink>http://www.ramkitech.com/2011/07/running-multiple-tomcat-instances-on.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-8181563140058186516</guid><pubDate>Tue, 05 Jul 2011 11:29:00 +0000</pubDate><atom:updated>2011-11-15T16:38:58.172+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">JSF</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">JSF 2.0</category><category domain="http://www.blogger.com/atom/ns#">Java EE 6</category><title>Understanding Java Server Faces 2.0  Part 3</title><description>&lt;span class="Apple-style-span" style="color: #333333; font-family: 'trebuchet ms', verdana, arial, sans-serif; font-size: x-small;"&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; line-height: 18px;"&gt;This is&amp;nbsp;Third&amp;nbsp; part of JSF 2.0 discussion. Please visit&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;a href="http://ramkitech.blogspot.com/2011/06/understanding-java-server-faces-20-part.html" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; color: #3366cc; font-family: 'trebuchet ms', verdana, arial, sans-serif; font-size: 13px; font-weight: bold; line-height: 18px;"&gt;part&amp;nbsp;one&amp;nbsp;&lt;/a&gt;&lt;span class="Apple-style-span" style="color: #333333; font-family: 'trebuchet ms', verdana, arial, sans-serif; font-size: x-small;"&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; line-height: 18px;"&gt;&amp;nbsp;and &lt;/span&gt;&lt;/span&gt;&lt;a href="http://ramkitech.blogspot.com/2011/06/understanding-java-server-faces-20-part_23.html" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; color: #333333; font-family: 'trebuchet ms', verdana, arial, sans-serif; font-size: 13px; line-height: 18px;"&gt;part two&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Update : &lt;a href="http://www.ramkitech.com/2011/11/jsf-jpa-jasperreports-ireport.html" target="_blank"&gt;New Post JasperReports in JSF&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
In this post we will discuss JSF with AJAX. In JSF 2.0 gives full support for ajax integration in web application.&amp;nbsp;&lt;span class="Apple-style-span" style="font-family: sans-serif; line-height: 19px;"&gt;With Ajax, web applications can send data to, and retrieve data from, a&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: sans-serif; line-height: 19px;"&gt;server&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: sans-serif;"&gt;&lt;span class="Apple-style-span" style="line-height: 19px;"&gt;asynchronously (in the background) without interfering with the display and behavior of the existing page. so with help of ajax we will make more interactive page. &amp;nbsp; JSF 2.0 Faclets provide &amp;lt;f:ajax&amp;gt; tag for&amp;nbsp;achieve&amp;nbsp;ajax in web application without writing client side&amp;nbsp;java script&amp;nbsp;ajax code. JSF 2.0&amp;nbsp;takes&amp;nbsp;care all of this.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: sans-serif;"&gt;&lt;span class="Apple-style-span" style="line-height: 19px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: sans-serif;"&gt;&lt;span class="Apple-style-span" style="line-height: 19px;"&gt;JSF and ajax&amp;nbsp;integration&amp;nbsp;is one of the&amp;nbsp;greatest&amp;nbsp;feature. and no other framework provide this much easy ajax integration in web application.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: sans-serif;"&gt;&lt;span class="Apple-style-span" style="line-height: 19px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: sans-serif;"&gt;&lt;span class="Apple-style-span" style="line-height: 19px;"&gt;Consider we have one simple web application it prompt the name and click submit button its display the name in same page in some where .&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: sans-serif;"&gt;&lt;span class="Apple-style-span" style="line-height: 19px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: sans-serif;"&gt;&lt;span class="Apple-style-span" style="line-height: 19px;"&gt;we will see this example without ajax&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: sans-serif;"&gt;&lt;span class="Apple-style-span" style="line-height: 19px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: sans-serif;"&gt;&lt;span class="Apple-style-span" style="line-height: 19px;"&gt;&lt;b&gt;&lt;u&gt;index.xhtml&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; white-space: normal;"&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman';"&gt;&lt;span class="Apple-style-span" style="white-space: normal;"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;html&lt;/span&gt; xmlns=&lt;span style="color: #2a00ff;"&gt;"http://www.w3.org/1999/xhtml"&lt;/span&gt;
      xmlns:h=&lt;span style="color: #2a00ff;"&gt;"http://java.sun.com/jsf/html"&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;h:&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;head&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;title&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;Facelet Title&lt;span style="color: #7f0055;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;title&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #7f0055;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;h:&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;head&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;h:&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;body&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;
      &lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;center&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;h1&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;JSF 2.0 Web Application&lt;span style="color: #7f0055;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;h1&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;br&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;/&amp;gt;&lt;/span&gt;

        &lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;h:&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;form&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;
          Enter Your Name 
          &lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;h:inputText&lt;/span&gt; value=&lt;span style="color: #2a00ff;"&gt;"#{demoBean.userName}"&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;h:commandButton&lt;/span&gt; value=&lt;span style="color: #2a00ff;"&gt;"Submit"&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;br&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;/&amp;gt;&lt;/span&gt;

          &lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;h2&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;
             &lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;h:outputLabel&lt;/span&gt; 
                    value=&lt;span style="color: #2a00ff;"&gt;"#{demoBean.sayHello()}"&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span style="color: #7f0055;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;h2&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;
       &lt;span style="color: #7f0055;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;h:&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;form&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;
     &lt;span style="color: #7f0055;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;center&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #7f0055;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;h:&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;body&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #7f0055;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;html&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; white-space: normal;"&gt;&lt;b&gt;&lt;u&gt;DemoBean.java&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;@ManagedBean
@SessionScoped
public class DemoBean {

    private String userName;

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String sayHello() {
        return "Hello, Mr." + userName;
    }
}
&lt;/pre&gt;
&lt;br /&gt;
here when we click the submit button then entire page is refreshed, ie. complete page is downloaded from server and displayed in browser.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="color: purple; font-size: large;"&gt;Integrate Ajax in JSF&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;JSF 2.0 provides full ajax support. so we no need to write client side&amp;nbsp;java script&amp;nbsp;for ajax. JSF 2.0 container generate client side java script, if we use &amp;lt;f:ajax&amp;gt; tag.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If we use &amp;lt;f:ajax&amp;gt; tag then JSF 2.0 container attached one java script file in generated&amp;nbsp;response code.&lt;br /&gt;
that java script handles all ajax related events/actions.&lt;br /&gt;
&lt;br /&gt;
now we change above example, add ajax in jsf&lt;br /&gt;
index.xhtml&lt;br /&gt;
&lt;pre style="background: #ffffff; color: black;"&gt;&amp;lt;?xml version='1.0' encoding='UTF-8' ?&amp;gt;

&lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;html&lt;/span&gt; xmlns=&lt;span style="color: #2a00ff;"&gt;"http://www.w3.org/1999/xhtml"&lt;/span&gt;
      xmlns:h=&lt;span style="color: #2a00ff;"&gt;"http://java.sun.com/jsf/html"&lt;/span&gt;
      xmlns:f=&lt;span style="color: #2a00ff;"&gt;"http://java.sun.com/jsf/core"&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;
  &lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;h:&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;head&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;title&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;Facelet Title&lt;span style="color: #7f0055;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;title&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;
  &lt;span style="color: #7f0055;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;h:&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;head&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;
  &lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;h:&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;body&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;
   &lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;center&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;
     &lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;h1&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;JSF 2.0 Web Application&lt;span style="color: #7f0055;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;h1&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;br&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;br&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;br&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;/&amp;gt;&lt;/span&gt;

      &lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;h:&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;form&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;
         Enter Your Name 
         &lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;h:inputText&lt;/span&gt; id=&lt;span style="color: #2a00ff;"&gt;"user_name"&lt;/span&gt; value=&lt;span style="color: #2a00ff;"&gt;"#{demoBean.userName}"&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;/&amp;gt;&lt;/span&gt;
         &lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;h:commandButton&lt;/span&gt; value=&lt;span style="color: #2a00ff;"&gt;"Submit"&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;f:ajax&lt;/span&gt; execute=&lt;span style="color: #2a00ff;"&gt;"user_name"&lt;/span&gt; render=&lt;span style="color: #2a00ff;"&gt;"display"&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;/&amp;gt;&lt;/span&gt;
         &lt;span style="color: #7f0055;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;h:commandButton&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;br&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;/&amp;gt;&lt;/span&gt;

         &lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;h2&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;  
           &lt;span style="color: #7f0055;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;h:outputLabel&lt;/span&gt; id=&lt;span style="color: #2a00ff;"&gt;"display"&lt;/span&gt; value=&lt;span style="color: #2a00ff;"&gt;"#{demoBean.sayHello()}"&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;/&amp;gt;&lt;/span&gt;
         &lt;span style="color: #7f0055;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;h2&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;
       &lt;span style="color: #7f0055;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;h:&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;form&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;
     &lt;span style="color: #7f0055;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;center&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #7f0055;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;h:&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;body&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #7f0055;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #7f0055; font-weight: bold;"&gt;html&lt;/span&gt;&lt;span style="color: #7f0055;"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;br /&gt;
here each component need id attribute. to distinguish between various components in page. &amp;lt;f:ajax&amp;gt; tags have some attributes. we nested inside the command button. so ajax event&amp;nbsp;occur&amp;nbsp;when command button clicked. Browser send ajax request to server. JSF 2.0 container&amp;nbsp;proceeds&amp;nbsp;the request and send partial response back to browser. JSF supplied java script takes care to parse the partial response and applied to DOM tree.&lt;br /&gt;
&lt;br /&gt;
this is partial response returned by container&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="xml" name="code"&gt;&lt;partial-response&gt;&lt;changes&gt;&lt;update id="j_idt8:display"&gt;Hello, Mr.541&lt;/update&gt;&lt;update id="javax.faces.ViewState"&gt;-4160405675642876717:7702620445641245519&lt;/update&gt;&lt;/changes&gt;&lt;/partial-response&gt;&lt;/pre&gt;
&lt;br /&gt;
we will see &amp;lt;f:ajax&amp;gt; tag attributes&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;execute&lt;/b&gt; - while send the ajax request what are the parameters(or form fields) attach with&amp;nbsp;request. here some predefined values are&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @all - all&amp;nbsp;components&amp;nbsp;value in the&amp;nbsp;page&amp;nbsp;are submitted,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @this- only one component where we attach ajax tag that component value is submitted,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @form - &amp;nbsp;current form (where ajax tag attached) fields are submitted&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;render&lt;/b&gt; - what are components we need to refresh (or update). here i mentioned 'display'. so only update the component whose id is display.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;event&lt;/b&gt; - when ajax request should happen. default value is click, when we attached with command Button. or default value is change ,when attache with input text. here possible values are&amp;nbsp;blur, change, valueChange, click, dblclick, focus,&amp;nbsp;keydown, keypress, keyup, mousedown, mousemove,&amp;nbsp;mouseout, mouseover, mouseup, select.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
now we modify the index.xhtml to call ajax event for every key up event.&lt;br /&gt;
&lt;pre class="xml" name="code"&gt;&lt;h:inputtext id="user_name" value="#{demoBean.userName}"&gt;
     &lt;f:ajax event="keyup" execute="user_name" render="display"&gt;
&lt;/f:ajax&gt;&lt;/h:inputtext&gt;&lt;/pre&gt;
&lt;br /&gt;
comments are welcomed&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;iframe allowfullscreen="" frameborder="0" height="390" src="http://www.youtube.com/embed/LnHW77oCCxU?rel=0&amp;amp;hd=1" width="640"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.mylivesignature.com/" target="_blank"&gt;&lt;img src="http://signatures.mylivesignature.com/54489/75/99C51E08D4042AD520EB268061366E79.png" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px !important; border-color: initial !important; border-left-width: 0px !important; border-right-width: 0px !important; border-style: initial !important; border-top-width: 0px !important;" /&gt;&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=Fgf_bshpPyk:ATCq_auXhaY:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=Fgf_bshpPyk:ATCq_auXhaY:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=Fgf_bshpPyk:ATCq_auXhaY:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?i=Fgf_bshpPyk:ATCq_auXhaY:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=Fgf_bshpPyk:ATCq_auXhaY:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ramki/feeds/~4/Fgf_bshpPyk" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ramki/feeds/~3/Fgf_bshpPyk/understanding-java-server-faces-20-part.html</link><author>noreply@blogger.com (Rama krishnnan E P)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://img.youtube.com/vi/LnHW77oCCxU/default.jpg" height="72" width="72" /><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /><feedburner:origLink>http://www.ramkitech.com/2011/07/understanding-java-server-faces-20-part.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-7763129603438428181</guid><pubDate>Thu, 23 Jun 2011 12:44:00 +0000</pubDate><atom:updated>2011-11-15T16:39:11.099+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">JSF</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">JSF 2.0</category><category domain="http://www.blogger.com/atom/ns#">Java EE 6</category><title>Understanding Java Server Faces 2.0 Part 2</title><description>&lt;span class="Apple-style-span" style="color: #666666; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 16px; line-height: 22px;"&gt;&lt;span class="Apple-style-span" style="color: blue; font-size: medium;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="color: black; font-family: 'Trebuchet MS', Trebuchet, sans-serif;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="font-size: xx-small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px;"&gt;This is&amp;nbsp;Second &amp;nbsp;part of JSF 2.0 discussion. Please visit&lt;/span&gt;&lt;/span&gt;&lt;a href="http://www.blogger.com/goog_606834479" style="color: #0f0fd4; text-decoration: none;"&gt;&amp;nbsp;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;&lt;a href="http://ramkitech.blogspot.com/2011/06/understanding-java-server-faces-20-part.html"&gt;&lt;span class="Apple-style-span" style="color: #0f0fd4;"&gt;part&amp;nbsp;one&lt;/span&gt;&amp;nbsp;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #666666; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 16px; line-height: 22px;"&gt;&lt;span class="Apple-style-span" style="color: blue; font-size: medium;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; line-height: 18px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
Update :&amp;nbsp;&lt;a href="http://www.ramkitech.com/2011/11/jsf-jpa-jasperreports-ireport.html" target="_blank"&gt;New Post JasperReports in JSF&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
In JSF 2.0 &lt;a href="http://ramkitech.blogspot.com/2011/06/understanding-java-server-faces-20-part.html"&gt;part 1&lt;/a&gt;&amp;nbsp; post, i used &amp;nbsp;@ManagedBean&amp;nbsp;annotation for POJO java class. Its OK,&amp;nbsp;actually&amp;nbsp;it derived from JSF 1.2.But we should use @Named&amp;nbsp;annotation&amp;nbsp;instead of @ManagedBean, if &lt;a href="http://ramkitech.blogspot.com/2011/06/contexts-and-dependency-injection.html"&gt;CDI&lt;/a&gt;&amp;nbsp;(&lt;span class="Apple-style-span" style="border-collapse: collapse; color: #333333; font-family: 'trebuchet ms', verdana, arial, sans-serif; line-height: 18px;"&gt;Contexts and Dependency Injection&lt;/span&gt;) environment is&amp;nbsp;available. I used Tomcat 7, its not Java EE 6 server and by default &lt;a href="http://ramkitech.blogspot.com/2011/06/contexts-and-dependency-injection.html"&gt;CDI&lt;/a&gt; is not&amp;nbsp;available.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;But we can use JBoss's &lt;a href="http://seamframework.org/Weld"&gt;Weld&lt;/a&gt; lib for&amp;nbsp;achieve&amp;nbsp;&lt;a href="http://ramkitech.blogspot.com/2011/06/contexts-and-dependency-injection.html"&gt;CDI&lt;/a&gt; in&amp;nbsp;tomcat&amp;nbsp;with minimal configuration. Weld is reference implementation of &lt;a href="http://ramkitech.blogspot.com/2011/06/contexts-and-dependency-injection.html"&gt;CDI&lt;/a&gt; and its comes standalone version also. This standalone version weld provide &lt;a href="http://ramkitech.blogspot.com/2011/06/contexts-and-dependency-injection.html"&gt;CDI&lt;/a&gt; environment for both Web Application and Java SE&amp;nbsp;application. By default &lt;a href="http://glassfish.java.net/"&gt;Glassfish&lt;/a&gt; 3.0/3.1 server comes with weld&amp;nbsp;&amp;nbsp;library&amp;nbsp;for CDI Environment. Here i am using Glassfish server with CDI enabled.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: purple; font-size: large;"&gt;&lt;b&gt;Page Navigation&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;This post we will&amp;nbsp;discuss page navigation in JSF2.0. Page Navigation means flow of the application. From one page to another page. In JSF1.2 page navigation is&amp;nbsp;achieved&amp;nbsp;through&amp;nbsp;&lt;b&gt;faces-config.xml&lt;/b&gt;&amp;nbsp;configuration file. But JSF 2.0 that configuration file is optional. JSF2.0 gives new feature is &lt;b&gt;Implicit Navigation&lt;/b&gt;. So in JSF2.0 we can use page navigation in two ways either implicit navigation or through configuration files. we will see the both.&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="color: purple; font-size: large;"&gt;Implicit Page Navigation&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;In Implicit navigation we can directly provide the next flow page in action attribute of JSF 2.0 tags. For example, we show one submit button in index.xhtml, when we click that button we should go to welcome.xhtml page &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="xml" name="code"&gt;&lt;h:commandbutton action="welcome" value="Submit"&gt;
&lt;/h:commandbutton&gt;&lt;/pre&gt;
&lt;br /&gt;
here action attribute just specify the &lt;b&gt;welcome&lt;/b&gt; or &lt;b&gt;welcome.xhtml&lt;/b&gt; directly. JSF 2.0 just pick the specific xhtml page and render that page.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="color: purple; font-size: large;"&gt;Through faces-config.xml file Page Navigation&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;In JSF 1.2 navigation flow is&amp;nbsp;achieved&amp;nbsp;only through faces-config.xml. Its look like navigation file in Struts.&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;index.xhtml&lt;/u&gt;&lt;br /&gt;
&lt;pre class="xml" name="code"&gt;&lt;h:form&gt;
      &lt;h:commandbutton action="success" value="Submit"&gt;&lt;/h:commandbutton&gt;
      &lt;h:commandbutton action="#{demoBean.showWelcome}" value="Submit"&gt;
      &lt;/h:commandbutton&gt;&lt;/h:form&gt;&lt;/pre&gt;
&lt;br /&gt;
In above JSF 2.0 code snippet they have two Submit Button. One have simple "success" literal in action&amp;nbsp;attribute&amp;nbsp;and another have one method in action attribute that method just return same "success" literal. Now JSF 2.0 first check in faces-config.xml, any navigation cases are match to the string literal, if matched then which to view id mentioned in faces-config.xml that page is rendered.&amp;nbsp;even&amp;nbsp;though&amp;nbsp;success.xhtml page is found. If not found in navigation cases then JSF2.0 try to do implict navigation. If&amp;nbsp;implicit&amp;nbsp;navigation&amp;nbsp;fails&amp;nbsp;then it show to client, page navigation is failed due to that page is not found.&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;DemoBean.java&lt;/u&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

@Named
@SessionScoped
public class DemoBean implements  Serializable{

    public String showWelcome()
    {
        // To do some bussiness logic
        return "success";
    }
}

&lt;/pre&gt;
So one thing is very important. faces-config.xml always take the high priority than implicit navigation, If its present.&lt;br /&gt;
&lt;u&gt;faces-config.xml&lt;/u&gt;&lt;br /&gt;
&lt;pre class="xml" name="code"&gt;&lt;faces-config version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"&gt;
    &lt;navigation-rule&gt;
        &lt;from-view-id&gt;/index.xhtml&lt;/from-view-id&gt;
        &lt;navigation-case&gt;
            &lt;from-outcome&gt;success&lt;/from-outcome&gt;
            &lt;to-view-id&gt;/welcome.xhtml&lt;/to-view-id&gt;
        &lt;/navigation-case&gt;
    &lt;/navigation-rule&gt;
&lt;/faces-config&gt;

&lt;/pre&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="color: purple; font-size: large;"&gt;Forward Vs Redirect&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Here we will discuss&amp;nbsp;difference&amp;nbsp;between forward and redirect. In JSF 2.0 by default it use forward only. For example if u run above example you can get following screen shots&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-DqP4KAjrPHc/TgMfRR-dSKI/AAAAAAAAB08/Lz-RBv5TC8U/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="97" src="http://1.bp.blogspot.com/-DqP4KAjrPHc/TgMfRR-dSKI/AAAAAAAAB08/Lz-RBv5TC8U/s320/1.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
when we click any submit button we get following welcome.xhtml page content. but still address bar pointing out index.xtml&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-L-ty1wWVCZM/TgMfWNhmWCI/AAAAAAAAB1A/N0riNOHljCQ/s1600/2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="97" src="http://4.bp.blogspot.com/-L-ty1wWVCZM/TgMfWNhmWCI/AAAAAAAAB1A/N0riNOHljCQ/s320/2.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
We&amp;nbsp;will&amp;nbsp;discuss how forwarding works in JSF2.0. if user clicks submit button post the values, if any, to index.xhtml. In index.xhtml page return the success string literal. In both implicit and explicit page navigation find appropriate welcome.xhtml and render that page and return the content to browser. Browser is not aware that result is return by same page or different page. So browser still think about result content is return by same page.&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-x-We_crxazM/TgMf9TsXm2I/AAAAAAAAB1E/wS6PY-H_LFE/s1600/forward.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="261" src="http://4.bp.blogspot.com/-x-We_crxazM/TgMf9TsXm2I/AAAAAAAAB1E/wS6PY-H_LFE/s400/forward.png" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Forwarding in JSF 2.0&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="color: purple; font-size: large;"&gt;Redirect&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; If you want to achive redirect in JSF 2.0. we should modify little bit. In Implicit Navigation we need to append "&lt;b&gt;?faces-redirect=true&lt;/b&gt;". then JSF 2.0 consider this navigation ask redirect instead of forwarding.&lt;br /&gt;
If you want redirect through faces-config.xml file page navigation, then add &lt;b&gt;&amp;lt;redirect/&amp;gt; &lt;/b&gt;tag in side &amp;lt;navigation-case&amp;gt; tag.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;index.xhtml&lt;/u&gt;&lt;br /&gt;
&lt;pre class="xml" name="code"&gt;&lt;h:form&gt;
      &lt;h:commandbutton action="welcome?faces-redirct=true" value="Submit"&gt;&lt;/h:commandbutton&gt;
      &lt;h:commandbutton action="#{demoBean.showWelcome}" value="Submit"&gt;
      &lt;/h:commandbutton&gt;&lt;/h:form&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;u&gt;faces-config.xml&lt;/u&gt;&lt;br /&gt;
&lt;pre class="xml" name="code"&gt;&lt;faces-config version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"&gt;
    &lt;navigation-rule&gt;
        &lt;from-view-id&gt;/index.xhtml&lt;/from-view-id&gt;
        &lt;navigation-case&gt;
            &lt;from-outcome&gt;success&lt;/from-outcome&gt;
            &lt;to-view-id&gt;/welcome.xhtml&lt;/to-view-id&gt;
            &lt;redirect&gt;   
        &lt;/redirect&gt;&lt;/navigation-case&gt;
    &lt;/navigation-rule&gt;
&lt;/faces-config&gt;
&lt;/pre&gt;
If we run the code with &lt;b&gt;&amp;lt;redirect/&amp;gt;&lt;/b&gt; tag or &lt;b&gt;?faces-redirect=true&lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-DqP4KAjrPHc/TgMfRR-dSKI/AAAAAAAAB08/Lz-RBv5TC8U/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="97" src="http://1.bp.blogspot.com/-DqP4KAjrPHc/TgMfRR-dSKI/AAAAAAAAB08/Lz-RBv5TC8U/s320/1.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
when user click the any submit button its shows welcome.xhtml page. Now see the address bar of the browser. Now its shows welcome.xhtml&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-QNIx8c_Kk-Q/TgMlghynXmI/AAAAAAAAB1Q/BFUm3V5T-r8/s1600/3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="104" src="http://1.bp.blogspot.com/-QNIx8c_Kk-Q/TgMlghynXmI/AAAAAAAAB1Q/BFUm3V5T-r8/s320/3.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="color: purple;"&gt;How Redirect is works?.&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Redirect is other hand. Now user click the submit button. Browser send the post the data to index.xtml. now index.xtml is processed. it return success literal and checks&amp;nbsp;whether&amp;nbsp;any redirect tag or implicit navigation ?faces-redirect=true are present or not. If it present the it simply return to browser with HTTP Status code 301. Its means the&amp;nbsp;resource&amp;nbsp;are&amp;nbsp;temporally&amp;nbsp;moved to another&amp;nbsp;location welcome.xhtml. When the browser gets 301 status code the again connect to new resource welcome.xhtml. Now welcome.xhtml processed in server and return the content. Now browser&amp;nbsp;render&amp;nbsp;and display the content. So when browser get the resource its update that URL into address bar. so now we get welcome.xhtml in address bar.&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-2cYmOtPAbSs/TgMgKbqzUQI/AAAAAAAAB1I/5h7IiZj8Uj8/s1600/redirect.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="275" src="http://4.bp.blogspot.com/-2cYmOtPAbSs/TgMgKbqzUQI/AAAAAAAAB1I/5h7IiZj8Uj8/s400/redirect.png" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Redirect in JSF 2.0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
Here Forwarding have some advantage over redirect.&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Forwarding makes both browser and server have more overhead and 2 connection need to establish.&lt;/li&gt;
&lt;li&gt;Redirect solve the form&amp;nbsp;re submission&amp;nbsp;problem. and its good design&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Forward is establish &amp;nbsp;two HTTP &amp;nbsp;connection. so overhead for both client and server. In some situation forward is best approach. consider the scenario you have one registation.xhtml page for registration form. User fill the data and click submit form fields are posted to server and updated either DB or List and return success/failed message &amp;nbsp;page show to user. In the case success/failed message page is shown but address bar is still point to &amp;nbsp;registation.xhtml. &amp;nbsp;Because its forwarding, so same URL is showing. Now user &amp;nbsp;click refresh button. then what happen? that page &amp;nbsp;is re-submitted every time when we click refresh. That issue we can solve through redirect.&lt;br /&gt;
&lt;br /&gt;
See the new screencast about this problem: &amp;nbsp;&lt;a href="http://www.youtube.com/watch?v=mkdn79S4TAM"&gt;http://www.youtube.com/watch?v=mkdn79S4TAM&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: blue; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="color: black; font-family: 'Trebuchet MS', Trebuchet, sans-serif;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="font-size: xx-small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px;"&gt;&amp;nbsp;Please visit&lt;/span&gt;&lt;/span&gt;&lt;a href="http://www.blogger.com/goog_606834479" style="color: #0f0fd4; text-decoration: none;"&gt;&amp;nbsp;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;&lt;span class="Apple-style-span" style="color: #0f0fd4;"&gt;&lt;a href="http://ramkitech.blogspot.com/2011/07/understanding-java-server-faces-20-part.html"&gt;part&amp;nbsp;&lt;/a&gt;three&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="border-collapse: collapse; color: #333333; font-family: 'trebuchet ms', verdana, arial, sans-serif; font-size: 13px; line-height: 18px;"&gt;&lt;b&gt;&lt;i&gt;Comments are welcomed&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;iframe allowfullscreen="" class="mp4downloader_embedButtonInitialized mp4downloader_tagChecked " frameborder="0" height="390" src="http://www.youtube.com/embed/kaF3yZX9x2k?rel=0" width="480"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.mylivesignature.com/" target="_blank"&gt;&lt;img src="http://signatures.mylivesignature.com/54489/75/99C51E08D4042AD520EB268061366E79.png" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-width: 0px !important; border-color: initial !important; border-left-width: 0px !important; border-right-width: 0px !important; border-style: initial !important; border-top-width: 0px !important;" /&gt;&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=CY36rvZVDiQ:r9pnV7e_OeI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=CY36rvZVDiQ:r9pnV7e_OeI:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=CY36rvZVDiQ:r9pnV7e_OeI:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?i=CY36rvZVDiQ:r9pnV7e_OeI:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=CY36rvZVDiQ:r9pnV7e_OeI:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ramki/feeds/~4/CY36rvZVDiQ" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ramki/feeds/~3/CY36rvZVDiQ/understanding-java-server-faces-20-part_23.html</link><author>noreply@blogger.com (Rama krishnnan E P)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-DqP4KAjrPHc/TgMfRR-dSKI/AAAAAAAAB08/Lz-RBv5TC8U/s72-c/1.png" height="72" width="72" /><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /><feedburner:origLink>http://www.ramkitech.com/2011/06/understanding-java-server-faces-20-part_23.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-5005400510994424778</guid><pubDate>Thu, 23 Jun 2011 08:02:00 +0000</pubDate><atom:updated>2011-06-23T13:33:18.354+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">CDI</category><category domain="http://www.blogger.com/atom/ns#">Java EE 6</category><title>Contexts and Dependency Injection Series</title><description>&lt;span class="Apple-style-span" style="color: #666666; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 16px; line-height: 22px;"&gt;&lt;span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: 14px; line-height: 21px;"&gt;Contexts and Dependency Injection (CDI )&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: 14px; line-height: 21px;"&gt;JSR 299&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: arial, verdana, helvetica, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 14px; line-height: 21px;"&gt;is a new feature in Java EE 6 Web Profile . &amp;nbsp;Its Enhance the JSR 330 Dependency Injection in&amp;nbsp;Java. CDI are highly used annotation. CDI makes Loose coupling between classes. To use javax.inject.Inject&amp;nbsp;annotation, we can inject any class into another classes&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
i put 4 part series of CDI, you can get it here&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #666666; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 16px; line-height: 22px;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h3 class="post-title entry-title" style="font: normal normal bold 24px/normal Neuton; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; position: relative;"&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://ramkitech.blogspot.com/2010/11/learning-cdi-contexts-and-dependency.html"&gt;&lt;span class="Apple-style-span" style="color: blue; font-size: small;"&gt;Learning CDI (Contexts and Dependency Injection) Part 1&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://ramkitech.blogspot.com/2010/12/learning-cdi-contexts-and-dependency.html"&gt;&lt;span class="Apple-style-span" style="color: blue; font-size: small;"&gt;Learning CDI (Contexts and Dependency Injection) Part 2&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://ramkitech.blogspot.com/2010/12/understanding-cdi-contexts-and.html"&gt;&lt;span class="Apple-style-span" style="color: blue; font-size: small;"&gt;Learning CDI (Contexts and Dependency Injection) Part 3&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://ramkitech.blogspot.com/2010/12/understanding-cdi-contexts-and_10.html"&gt;&lt;span class="Apple-style-span" style="color: blue; font-size: small;"&gt;Learning CDI (Contexts and Dependency Injection) Part 4&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/h3&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.mylivesignature.com/" target="_blank"&gt;&lt;img src="http://signatures.mylivesignature.com/54489/75/99C51E08D4042AD520EB268061366E79.png" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-width: 0px !important; border-color: initial !important; border-left-width: 0px !important; border-right-width: 0px !important; border-style: initial !important; border-top-width: 0px !important;" /&gt;&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=RmFPnMh8l3E:xiUC4Wo7Neo:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=RmFPnMh8l3E:xiUC4Wo7Neo:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=RmFPnMh8l3E:xiUC4Wo7Neo:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?i=RmFPnMh8l3E:xiUC4Wo7Neo:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=RmFPnMh8l3E:xiUC4Wo7Neo:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ramki/feeds/~4/RmFPnMh8l3E" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ramki/feeds/~3/RmFPnMh8l3E/contexts-and-dependency-injection.html</link><author>noreply@blogger.com (Rama krishnnan E P)</author><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /><feedburner:origLink>http://www.ramkitech.com/2011/06/contexts-and-dependency-injection.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-1052762209377006055</guid><pubDate>Tue, 21 Jun 2011 06:26:00 +0000</pubDate><atom:updated>2011-07-22T14:59:27.202+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">JSF</category><category domain="http://www.blogger.com/atom/ns#">JSF 2.0</category><category domain="http://www.blogger.com/atom/ns#">Java EE 6</category><title>Why should I learn JSF</title><description>Java Server Faces (JSF) is one of the presentation web frameworks in java. There is lots of others&amp;nbsp;frameworks&amp;nbsp;like Spring, GWT, Wickets, Struts. Today this post we ll discuss why JSF is more important then others.Here I am not&amp;nbsp;&lt;span class="Apple-style-span" style="font-family: arial, verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"&gt;criticize any frameworks. i just talking about JSF.&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In JSF 1.2 and previous version of JSF used JSP as a view&amp;nbsp;declarative&amp;nbsp;language and JSP life cycle is not matched with JSF and ajax requests. JSF 1.2 are complex to use and they have some short coming in feature.&lt;br /&gt;
&lt;br /&gt;
But JSF 2 is completely changed the&amp;nbsp;adapt lots of technologies,&amp;nbsp;but still its support backward&amp;nbsp;compatible.Its very easy to learn. More over JSF is center piece in Java EE 6 Spec. It means that what are the new components or specification introduced in Java EE 6 are seamlessly integrated into JSF. Because those components spec is designed for JSF in mind.&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;New&amp;nbsp;Components&amp;nbsp;/ Specification added in Java EE6 spec&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;CDI 1.0 (Contexts and Dependency Injection)&lt;/li&gt;
&lt;li&gt;Bean Validation 1.0&lt;/li&gt;
&lt;li&gt;Java Persistence API 2.0&lt;/li&gt;
&lt;li&gt;EL 2.2 (Expression Language)&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
Above spec is added in Java EE 6 and well integration with JSF. JSF comes with basic components of HTML User Interface (UI). JSF is extensible. So with help of third party&amp;nbsp;libraries like &lt;a href="http://www.primefaces.org/showcase-labs/"&gt;PrimeFaces&lt;/a&gt;, &lt;a href="http://www.icefaces.org/"&gt;IceFaces&lt;/a&gt;, &lt;a href="http://www.oracle.com/technetwork/developer-tools/adf/overview/index.html"&gt;ADF Faces&lt;/a&gt;, ...&amp;nbsp; &amp;nbsp;gives Rich UI. &lt;br /&gt;
&lt;br /&gt;
When JSF 2 spec is gives direct&amp;nbsp;competition&amp;nbsp;to other web&amp;nbsp;frameworks. JSF derive lots of good feature from Spring, GWT, Seam Framework.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&amp;nbsp;Why should I learn JSF&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;JSF spec is controlled by JCP (Java Community Process) and its standard for Java EE server&lt;/li&gt;
&lt;li&gt;There is no vendor locking, because JSF is spec, we can use any implementation of JSF, for example&amp;nbsp;&lt;a href="http://javaserverfaces.java.net/"&gt;Mojarra&lt;/a&gt;,&amp;nbsp;&lt;a href="http://myfaces.apache.org/"&gt;MyFaces&lt;/a&gt;&amp;nbsp;are JSF2.0&amp;nbsp;implementation.&lt;/li&gt;
&lt;li&gt;JSF is part of Java EE 6. so when your server is Java EE 6 compliant server. then its must support JSF 2. so no need to&amp;nbsp;configure&amp;nbsp;externally and no need to put web framework jar in class path.&lt;/li&gt;
&lt;li&gt;In Java CDI is direct&amp;nbsp;compete&amp;nbsp;with DI in Spring and&amp;nbsp;Guice in Google . In JSF 2 Navigation Component is&amp;nbsp;compete&amp;nbsp;with Spring Web Flow. JSF 2's Ajax Framework components compete with GWT. so what i conclude here, each and every component is good/best&lt;/li&gt;
&lt;li&gt;In JSF 2 is easy to&amp;nbsp;implement&amp;nbsp;with help of annotation. Annotation is makes all&amp;nbsp;configuration&amp;nbsp;files are optional. No more XML. Now Spring start supporting annotation instead of&amp;nbsp;XML&amp;nbsp;configuration.&lt;/li&gt;
&lt;li&gt;Java EE components like CDI, Bean Validation, JPA are&amp;nbsp;standardized&amp;nbsp;and used in Enterprise Level and Java SE also. But other frameworks components are de-facto standard.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;!-- adsense --&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Java EE 5 had a big gap for enterprise application so we need those frameworks to fill the gap. but Java EE6 mostly fill the gap. If your working in Java EE 5&amp;nbsp;compliant&amp;nbsp;server then you should go with those frameworks. &amp;nbsp;&lt;/li&gt;
&lt;li&gt;If you take case study of JPA, before JPA come into picture, EJB 2.1 use persistent entity classes for&amp;nbsp;persistent. its very difficult to study. Then Spring comes with easy&amp;nbsp;solution POJO class used for&amp;nbsp;persistent.&amp;nbsp; then JPA comes with improved&amp;nbsp;solution&amp;nbsp;with&amp;nbsp;help&amp;nbsp;of annotation. Now JPA is standard for all ORM&amp;nbsp;libraries&amp;nbsp;like Hibernate, EclipseLink, &amp;nbsp;etc.. Now EJB 3.1 uses JPA 2.0 is&amp;nbsp;persistent&amp;nbsp;purpose.&lt;/li&gt;
&lt;li&gt;&amp;nbsp;Now Spring start support for CDI, Bean validation and other components in Java EE 6&lt;/li&gt;
&lt;li&gt;Even you can easily&amp;nbsp;integrate&amp;nbsp;JSF pages in Spring&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="color: red; font-size: large;"&gt;If anything i mentioned wrong please put your thought in comments.&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="color: red; font-size: large;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Please Check &lt;/span&gt;&lt;span class="Apple-style-span" style="color: red; font-size: large;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span class="Apple-style-span" style="color: #666666; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; line-height: 15px;"&gt;&lt;a href="http://ramkitech.blogspot.com/2011/06/understanding-java-server-faces-20-part.html" style="color: #2198a6; text-decoration: underline;"&gt;Understanding Java Server Faces 2.0 Part 1&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: sans-serif;"&gt;&lt;span class="Apple-style-span" style="line-height: 19px;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Droid Serif';"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;&lt;a href="http://www.dzone.com/links/r/understanding_java_server_faces_20_part_2.html"&gt;Understanding Java Server Faces 2.0 &amp;nbsp;Part&lt;/a&gt;&amp;nbsp;2&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="color: red;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;a href="http://www.mylivesignature.com/" target="_blank"&gt;&lt;img src="http://signatures.mylivesignature.com/54489/75/99C51E08D4042AD520EB268061366E79.png" style="background: transparent; border: 0 !important;" /&gt;&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=M5k98y6pzmU:MaX6esLD6xE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=M5k98y6pzmU:MaX6esLD6xE:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=M5k98y6pzmU:MaX6esLD6xE:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?i=M5k98y6pzmU:MaX6esLD6xE:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=M5k98y6pzmU:MaX6esLD6xE:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ramki/feeds/~4/M5k98y6pzmU" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ramki/feeds/~3/M5k98y6pzmU/why-should-i-learn-jsf.html</link><author>noreply@blogger.com (Rama krishnnan E P)</author><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /><feedburner:origLink>http://www.ramkitech.com/2011/06/why-should-i-learn-jsf.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-8608148130077149763</guid><pubDate>Sat, 18 Jun 2011 13:03:00 +0000</pubDate><atom:updated>2011-07-22T14:57:24.303+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">JSF</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">JSF 2.0</category><category domain="http://www.blogger.com/atom/ns#">Java EE 6</category><title>Understanding Java Server Faces 2.0  Part 1</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: sans-serif;"&gt;&lt;span class="Apple-style-span" style="line-height: 19px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: sans-serif;"&gt;&lt;span class="Apple-style-span" style="line-height: 19px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: sans-serif;"&gt;&lt;span class="Apple-style-span" style="line-height: 19px;"&gt;Update : I put new post for&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Droid Serif';"&gt;&lt;a href="http://ramkitech.blogspot.com/2011/06/why-should-i-learn-jsf.html"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;Why should I learn JSF&lt;/span&gt;&lt;/a&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: sans-serif;"&gt;&lt;span class="Apple-style-span" style="line-height: 19px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; I put new post for&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Droid Serif';"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;&lt;a href="http://www.dzone.com/links/r/understanding_java_server_faces_20_part_2.html"&gt;Understanding Java Server Faces 2.0 &amp;nbsp;Part&lt;/a&gt;&amp;nbsp;2&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Droid Serif';"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: sans-serif; line-height: 19px;"&gt;JavaServer Faces&amp;nbsp;(JSF) is a&amp;nbsp;Java-based&amp;nbsp;Web application framework&amp;nbsp;intended to simplify&amp;nbsp;development&amp;nbsp;integration of web-based&amp;nbsp;user interfaces.&amp;nbsp;&lt;/span&gt;Java Server Faces (JSF) 2.0 is a improved component of Java EE 6&amp;nbsp;Specification.&amp;nbsp;&amp;nbsp;Its Component based model.&amp;nbsp;Its is alternative technology for Struts, JSP, Spring. Its MVC (Model-View-Controller) based architecture.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="text-align: justify;"&gt;If JSF 2.0 is compared to its previous version JSF 1.2, &amp;nbsp;there are more&amp;nbsp;functionality&amp;nbsp;are added&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Facelets is a default View Declartion Language (VDL)&lt;/li&gt;
&lt;li&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Full spport for AJAX&lt;/li&gt;
&lt;li&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Composite components&lt;/li&gt;
&lt;li&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Beans Validation&lt;/li&gt;
&lt;li&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Implicit navigation&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;Facelets&lt;/b&gt;&lt;br /&gt;
Facelets used to describe the UI in tag styled format. Its extension is .xhtml and application usually accessed in .jsf, .faces, .xhtml . we can configure in web.xml.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Lifecycle of JSF&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-KaPo9AjfBnc/TfyTM5MDscI/AAAAAAAAB0k/PzQOrqnb_tI/s1600/Capture.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-KaPo9AjfBnc/TfyTM5MDscI/AAAAAAAAB0k/PzQOrqnb_tI/s1600/Capture.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The&amp;nbsp;above&amp;nbsp;diagram is JSF life cycle. we&amp;nbsp;explain this&amp;nbsp;life cycle with sample JSF Application&lt;br /&gt;
&lt;br /&gt;
we have 2 JSF pages and one bean java class&lt;br /&gt;
&lt;br /&gt;
&lt;!-- adsense --&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;index.xhtml&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre style="background: #ffffff; color: black;"&gt;&amp;lt;?xml version='&lt;span style="color: #008c00;"&gt;1.0&lt;/span&gt;' encoding='UTF-&lt;span style="color: #008c00;"&gt;8&lt;/span&gt;' ?&amp;gt;
&lt;span style="color: #004a43;"&gt;&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "&lt;/span&gt;&lt;span style="color: #5555dd;"&gt;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&lt;/span&gt;&lt;span style="color: #004a43;"&gt;"&amp;gt;&lt;/span&gt;
&lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;html&lt;/span&gt;&lt;span style="color: #274796;"&gt; xmlns&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"http://www.w3.org/1999/xhtml"&lt;/span&gt;&lt;span style="color: #274796;"&gt;&lt;/span&gt;
&lt;span style="color: #274796;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xmlns:h&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"http://java.sun.com/jsf/html"&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;h:&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;head&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;title&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;Sample JSF Application&lt;span style="color: #a65700;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;title&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #a65700;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;h:&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;head&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;h:&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;body&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;h:&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;form&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;
            Enter your Name 
            &lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;h:inputText&lt;/span&gt;&lt;span style="color: #274796;"&gt; &lt;/span&gt;&lt;span style="color: #074726;"&gt;value&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"#{demoBean.name}"&lt;/span&gt;&lt;span style="color: #274796;"&gt; required&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"true"&lt;/span&gt;&lt;span style="color: #274796;"&gt; &lt;/span&gt;&lt;span style="color: #a65700;"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;h:commandButton&lt;/span&gt;&lt;span style="color: #274796;"&gt; &lt;/span&gt;&lt;span style="color: #074726;"&gt;value&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"Submit"&lt;/span&gt;&lt;span style="color: #274796;"&gt; &lt;/span&gt;&lt;span style="color: #074726;"&gt;action&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"welcome"&lt;/span&gt;&lt;span style="color: #274796;"&gt; &lt;/span&gt;&lt;span style="color: #a65700;"&gt;/&amp;gt;&lt;/span&gt;
            
        &lt;span style="color: #a65700;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;h:&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;form&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #a65700;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;h:&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;body&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a65700;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;html&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: purple;"&gt;&lt;u&gt;&lt;b&gt;welcome.xhtml&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre style="background: #ffffff; color: black;"&gt;&amp;lt;?xml version='&lt;span style="color: #008c00;"&gt;1.0&lt;/span&gt;' encoding='UTF-&lt;span style="color: #008c00;"&gt;8&lt;/span&gt;' ?&amp;gt;
&lt;span style="color: #004a43;"&gt;&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "&lt;/span&gt;&lt;span style="color: #5555dd;"&gt;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&lt;/span&gt;&lt;span style="color: #004a43;"&gt;"&amp;gt;&lt;/span&gt;
&lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;html&lt;/span&gt;&lt;span style="color: #274796;"&gt; xmlns&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"http://www.w3.org/1999/xhtml"&lt;/span&gt;&lt;span style="color: #274796;"&gt;&lt;/span&gt;
&lt;span style="color: #274796;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xmlns:h&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"http://java.sun.com/jsf/html"&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;h:&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;head&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;title&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;Welcome Page&lt;span style="color: #a65700;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;title&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #a65700;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;h:&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;head&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;h:&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;body&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;
        Hello #{demoBean&lt;span style="color: #008c00;"&gt;.&lt;/span&gt;name}
    &lt;span style="color: #a65700;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #5f5035;"&gt;h:&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;body&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #a65700;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;html&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: purple;"&gt;&lt;b&gt;&lt;u&gt;DemoBean.java&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ramki.bean;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author ramki
 */
@ManagedBean()
@SessionScoped
public class DemoBean {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}
&lt;/pre&gt;&lt;br /&gt;
here each web page uses the facelet tag library&lt;br /&gt;
&lt;br /&gt;
&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: #a65700;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;html&lt;/span&gt;&lt;span style="color: #274796;"&gt; xmlns&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"http://www.w3.org/1999/xhtml"&lt;/span&gt;&lt;span style="color: #274796;"&gt;&lt;/span&gt;
&lt;span style="color: #274796;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xmlns:h&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;"http://java.sun.com/jsf/html"&lt;/span&gt;&lt;span style="color: #a65700;"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;so, we need to add the tag library in html with prefix 'h' by default.&lt;br /&gt;
&lt;br /&gt;
each HTML UI elements like text field, button, checkbox, etc... Facelets has equal tags to fullfill the standard UI like &amp;lt;h:inputText&amp;gt;, &amp;lt;h:commandButton&amp;gt;,etc...&lt;br /&gt;
&lt;br /&gt;
when we execute this application index.xhtml page is translated into views. View is collection of UI components arranged paricular manner. for example our index.xhtml page turns into View&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-1N2Q_Xj1h5M/TfyZUpMxMlI/AAAAAAAAB0o/O02V72evkxc/s1600/Capture1.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="322" src="http://4.bp.blogspot.com/-1N2Q_Xj1h5M/TfyZUpMxMlI/AAAAAAAAB0o/O02V72evkxc/s400/Capture1.PNG" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;View Tree of index.xhtml page&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;UIViewRoot &lt;/b&gt;is Top level components add HtmlOutputHead and&amp;nbsp;&amp;nbsp;HtmlOutputBody. These 2 components translated in &amp;lt;head&amp;gt; and &amp;lt;body&amp;gt; tag in Render phase. In body component has input text field and command button components.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If browser request index.html first time the Phase 1 &amp;amp; 6 only executed all other phases are bypassed&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="color: #4c1130;"&gt;Phase 1 : Create / Restore View&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
Every JSf page is create the view. the that view is cached for future use. for example index.html page is requested by browser then container search index.xhtml view tree. Above diagram is view tree of index.xhtml page.If found in cache the restore the view, otherwise create the view tree.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="color: #4c1130;"&gt;Phase 6 : Render the View&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;JSF have Render Kit to render the view to generate appropriate format. for example HTML render kit generate html code from view. Render kit knows how to render the UI components.&lt;br /&gt;
&lt;br /&gt;
now user fill some details in index.xhtml the click some action the same page is requested to server now this time index.xhtml tree view is restored and run all remaining phases.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="color: #4c1130;"&gt;Phase 3: Apply values from User to View&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;if user sends some data like POST or GET form values, this phases apply this values to the Tree View like fooling diagram&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-bcRzsQ6Yl94/Tfydnpq2oSI/AAAAAAAAB0w/1BEtEOHpmNs/s1600/Capture2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="323" src="http://2.bp.blogspot.com/-bcRzsQ6Yl94/Tfydnpq2oSI/AAAAAAAAB0w/1BEtEOHpmNs/s400/Capture2.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="color: #4c1130;"&gt;Phase 4: Validate the values&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;This is optional phase. if any&amp;nbsp;validations&amp;nbsp;is mentioned then this phases is executed. otherwise it simply bypassed. for example in index.xhtml input text field we mentioned&lt;b&gt; required=true&lt;/b&gt; its one of the validation. so if submit the form without filling values this phases reporting exception and forward to directly render phase. all other phaes are bypassed. if this phases execute without exception the phase 5 is executed&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="color: #4c1130;"&gt;Phase 5: Fetch New View&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;In this phases is responsible for find the next view to render and&amp;nbsp;displayed&amp;nbsp;to user. for example our example in command button has action property to mentioned &lt;i&gt;welcome &lt;/i&gt;value. in this phase find the welcome.xhtml page and gives to render phase. here we used implicit navigation its one of the features of JSF 2.0&lt;br /&gt;
&lt;br /&gt;
When we run the above example&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-gferx_WEzgY/TfygWHg3owI/AAAAAAAAB00/L0Kwe84fJjc/s1600/Capture3.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="94" src="http://2.bp.blogspot.com/-gferx_WEzgY/TfygWHg3owI/AAAAAAAAB00/L0Kwe84fJjc/s320/Capture3.PNG" width="320" /&gt;&lt;span class="Apple-style-span" style="-webkit-text-decorations-in-effect: none; color: black;"&gt;&lt;/span&gt;&lt;/a&gt;&lt;a href="http://1.bp.blogspot.com/-wAFD-9XbUn8/TfygbDiKkzI/AAAAAAAAB04/j8s0R4y_qDE/s1600/Capture4.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="110" src="http://1.bp.blogspot.com/-wAFD-9XbUn8/TfygbDiKkzI/AAAAAAAAB04/j8s0R4y_qDE/s400/Capture4.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: sans-serif;"&gt;&lt;span class="Apple-style-span" style="line-height: 19px;"&gt;Update : I put new post for&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Droid Serif';"&gt;&lt;a href="http://ramkitech.blogspot.com/2011/06/why-should-i-learn-jsf.html"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;Why should I learn JSF&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: sans-serif;"&gt;&lt;span class="Apple-style-span" style="line-height: 19px;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;I put new post for&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Droid Serif';"&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;&lt;a href="http://www.dzone.com/links/r/understanding_java_server_faces_20_part_2.html"&gt;Understanding Java Server Faces 2.0 &amp;nbsp;Part&lt;/a&gt;&amp;nbsp;2&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-family: 'Droid Serif';"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;br /&gt;
Watch the you tube with 480p or 720p&lt;br /&gt;
&lt;br /&gt;
&lt;iframe allowfullscreen="" frameborder="0" height="390" src="http://www.youtube.com/embed/JHsBX_HQsaw?rel=0" width="640"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; color: #333333; font-family: 'trebuchet ms', verdana, arial, sans-serif; font-size: 13px; line-height: 18px;"&gt;&lt;b&gt;&lt;i&gt;Comments are welcomed&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; color: #333333; font-family: 'trebuchet ms', verdana, arial, sans-serif; font-size: 13px; line-height: 18px;"&gt;&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; color: #333333; font-family: 'trebuchet ms', verdana, arial, sans-serif; font-size: 13px; line-height: 18px;"&gt;&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;By&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://www.mylivesignature.com/" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em; text-align: justify;" target="_blank"&gt;&lt;img src="http://signatures.mylivesignature.com/54489/75/99C51E08D4042AD520EB268061366E79.png" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-width: 0px !important; border-color: initial !important; border-left-width: 0px !important; border-right-width: 0px !important; border-style: initial !important; border-top-width: 0px !important;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="text-align: right;"&gt;&lt;a href="http://www.mylivesignature.com/" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em; text-align: justify;" target="_blank"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;a href="http://www.mylivesignature.com/" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em; text-align: justify;" target="_blank"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=4KwMDjUOoxw:ZZQ0vvuXZMU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=4KwMDjUOoxw:ZZQ0vvuXZMU:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=4KwMDjUOoxw:ZZQ0vvuXZMU:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?i=4KwMDjUOoxw:ZZQ0vvuXZMU:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=4KwMDjUOoxw:ZZQ0vvuXZMU:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ramki/feeds/~4/4KwMDjUOoxw" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ramki/feeds/~3/4KwMDjUOoxw/understanding-java-server-faces-20-part.html</link><author>noreply@blogger.com (Rama krishnnan E P)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-KaPo9AjfBnc/TfyTM5MDscI/AAAAAAAAB0k/PzQOrqnb_tI/s72-c/Capture.PNG" height="72" width="72" /><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /><feedburner:origLink>http://www.ramkitech.com/2011/06/understanding-java-server-faces-20-part.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-5982299635951438025</guid><pubDate>Fri, 10 Dec 2010 08:10:00 +0000</pubDate><atom:updated>2012-04-10T10:27:57.341+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">CDI</category><category domain="http://www.blogger.com/atom/ns#">Java EE 6</category><title>Understanding CDI (Contexts and Dependency Injection) Part 4</title><description>&lt;span class="Apple-style-span" style="color: blue; font-size: large;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="color: black; font-family: 'Trebuchet MS', Trebuchet, sans-serif;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px;"&gt;This is&amp;nbsp;Fourth &amp;nbsp;part of CDI discussion.Please visit&lt;/span&gt;&lt;/span&gt;&lt;a href="http://www.blogger.com/goog_606834479"&gt;&amp;nbsp;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;&lt;a href="http://ramkitech.blogspot.com/2010/11/learning-cdi-contexts-and-dependency.html"&gt;part&amp;nbsp;one&lt;/a&gt;,&amp;nbsp;&lt;a href="http://ramkitech.blogspot.com/2010/12/learning-cdi-contexts-and-dependency.html"&gt;part two&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: x-small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px; line-height: 18px;"&gt;&amp;nbsp;&lt;a href="http://ramkitech.blogspot.com/2010/12/understanding-cdi-contexts-and.html"&gt;part three&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: blue; font-size: large;"&gt;&lt;span class="Apple-style-span" style="color: black; font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: x-small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: blue; font-size: large;"&gt;Interceptors&lt;/span&gt;&lt;br /&gt;
Interceptors is one feature of CDI. Using this feature we can intercept the method call. Its counterpart technique for Aspect Oriented Programming (AOP) in Spring. Its helps to&amp;nbsp;analysis&amp;nbsp;the&amp;nbsp;business&amp;nbsp;methods and these interceptors are disabled by default. so we can enable/disable the interceptor in&amp;nbsp;deployment&amp;nbsp;time through beans.xml &amp;nbsp;file.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: large;"&gt;Create interceptor&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; To create interceptor involves two step process. first to create interceptor binding and &amp;nbsp;implement the interceptors.&lt;br /&gt;
&lt;br /&gt;
here we create Log Interceptor, so we need to create Log&amp;nbsp;Interceptor&amp;nbsp;Binding(its &amp;nbsp;like qualifier)&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;Log.java&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;package org.ramki.interceptor;

import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.interceptor.InterceptorBinding;

/**
 *
 * @author Ramakrishnan
 */
@Inherited
@InterceptorBinding
@Retention(RUNTIME)
@Target({METHOD, TYPE})
public @interface Log {
}
&lt;/pre&gt;&lt;br /&gt;
here @InterceptorBinding is represent that the annotation 'Log' is interceptor&lt;br /&gt;
&lt;br /&gt;
second, we need to implement the interceptors&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;LogImpl.java&lt;/u&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;package org.ramki.interceptor.impl;

import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;
import org.ramki.interceptor.Log;

/**
 *
 * @author Ramakrishnan
 */

@Interceptor
@Log

public class LogImpl {

    @AroundInvoke
    public Object logging(InvocationContext context) throws Exception
    {
        System.out.println("Log before method call...");
        Object returnObject = context.proceed();
                // to do some logging
        System.out.println("Log after method call...");
        return returnObject;
    }
}
&lt;/pre&gt;&lt;br /&gt;
here @Interceptor represent that its interceptor implementation&lt;br /&gt;
@Log specifies to which interceptor &amp;nbsp;implementation , both of these lines shows that this &amp;nbsp;class is Log interceptor Implementation&lt;br /&gt;
&lt;br /&gt;
@AroundInvoke is comes before one method defines&lt;br /&gt;
that method must pass the below&amp;nbsp;method&amp;nbsp;signature&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style="background-color: #ffe599;"&gt;public &amp;nbsp; &amp;nbsp;Object &amp;nbsp; &amp;nbsp;&amp;lt;methodName&amp;gt; (InvocationContext context)&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
here&amp;nbsp;methodName is any name we can give.&lt;br /&gt;
in that method call &amp;nbsp;&lt;span style="background-color: #fff2cc;"&gt;context.proceed() &lt;/span&gt;- to call&amp;nbsp;actual&amp;nbsp;method &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
so when we call any intercepted method then the container calls this method and here do pre-processing then call&amp;nbsp;actual&amp;nbsp;method through&amp;nbsp;&amp;nbsp;context.proceed() and finally we can do some post-processing...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: blue;"&gt;Apply Interceptor&lt;/span&gt;&lt;br /&gt;
Once interceptor is ready, then we can apply any business class&lt;br /&gt;
&lt;u&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;SimeClass.java&lt;/span&gt;&lt;/u&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;package org.ramki.beans;

import org.ramki.interceptor.Log;
import org.ramki.interceptor.Time;
/**
 *
 * @author Ramakrishnan
 */


@Log


public class SomeClass {

    public void methodA() {
        System.out.println("indide methodA...");
    }

    public void methodB() {
        System.out.println("indide methodB...");
    }

    public void methodC() {
        System.out.println("indide methodC...");
    }

    public void methodD() {
        System.out.println("indide methodD...");
    }

    public void methodE() {
        System.out.println("indide methodE...");
    }
}
&lt;/pre&gt;&lt;br /&gt;
here i put @Log in class level. we can put method level also (i.e we can put some methods )&lt;br /&gt;
&lt;br /&gt;
Interceptor is disabled by default. so we need to enable through beans.xml&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="xml" name="code"&gt;&lt;beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"&gt;


           &lt;interceptors&gt;
                &lt;class&gt;org.ramki.interceptor.impl.LogImpl&lt;/class&gt;
           &lt;/interceptors&gt;
&lt;/beans&gt;
&lt;/pre&gt;&lt;br /&gt;
Through servlet/jsp if u try to call business method of SomeClass class, its do all pre and post processing through interceptors.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; color: #333333; font-family: 'trebuchet ms', verdana, arial, sans-serif; font-size: 13px; line-height: 18px;"&gt;&lt;b&gt;&lt;i&gt;Comments are welcomed&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; color: #333333; font-family: 'trebuchet ms', verdana, arial, sans-serif; font-size: 13px; line-height: 18px;"&gt;&lt;b&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;Scree cast&lt;/b&gt;&lt;br /&gt;
please watch video in HQ mode&lt;br /&gt;
&lt;object height="745" width="960"&gt;&lt;param name="movie" value="http://www.youtube.com/e/vKXS8rrt6A4?hd=1&amp;amp;color1=0xcc2550&amp;amp;color2=0xe87a9f"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/e/vKXS8rrt6A4?hd=1&amp;amp;color1=0xcc2550&amp;amp;color2=0xe87a9f" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="960" height="745"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; color: #333333; font-family: 'trebuchet ms', verdana, arial, sans-serif; font-size: 13px; line-height: 18px;"&gt;&lt;b&gt;&lt;i&gt;Comments are welcomed&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=HU670PIA7S8:-ItsSINwqZc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=HU670PIA7S8:-ItsSINwqZc:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=HU670PIA7S8:-ItsSINwqZc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?i=HU670PIA7S8:-ItsSINwqZc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=HU670PIA7S8:-ItsSINwqZc:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ramki/feeds/~4/HU670PIA7S8" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ramki/feeds/~3/HU670PIA7S8/understanding-cdi-contexts-and_10.html</link><author>noreply@blogger.com (Rama krishnnan E P)</author><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /><feedburner:origLink>http://www.ramkitech.com/2010/12/understanding-cdi-contexts-and_10.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-6884701445357745652</guid><pubDate>Mon, 06 Dec 2010 06:56:00 +0000</pubDate><atom:updated>2011-07-22T15:00:49.200+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">CDI</category><category domain="http://www.blogger.com/atom/ns#">Java EE 6</category><title>Understanding CDI (Contexts and Dependency Injection) Part 3</title><description>&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', Trebuchet, sans-serif;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px;"&gt;This is&amp;nbsp;Third&amp;nbsp; part of CDI discussion.Please visit&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;a href="http://ramkitech.blogspot.com/2010/11/learning-cdi-contexts-and-dependency.html#chitikatest=CDI" style="color: #b52b43; font-family: 'Trebuchet MS', Trebuchet, sans-serif; line-height: 18px; text-decoration: none;"&gt;first part&lt;/a&gt;&amp;nbsp;and &lt;a href="http://ramkitech.blogspot.com/2010/12/learning-cdi-contexts-and-dependency.html"&gt;part two&lt;/a&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px; line-height: 18px;"&gt;,&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', Trebuchet, sans-serif;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;b&gt;@Alternative&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px; line-height: 18px;"&gt;In part &lt;/span&gt;&lt;/span&gt;&lt;a href="http://ramkitech.blogspot.com/2010/12/learning-cdi-contexts-and-dependency.html" style="font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; line-height: 18px;"&gt;two&lt;/a&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px; line-height: 18px;"&gt;&amp;nbsp;we seen @qualifier 's to resolve the&amp;nbsp;unambiguous&amp;nbsp;problem for one interface and more than on implementation. In qualifier helps to solve in&amp;nbsp;development&amp;nbsp;time. (i.e all meta information is stored in class files).&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px; line-height: 18px;"&gt;Another&amp;nbsp;solution is @Alternative annotation solve the problem in&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: 13px; line-height: 18px;"&gt;deployment&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px; line-height: 18px;"&gt;&amp;nbsp;time. all&amp;nbsp;configuration&amp;nbsp;is stored in beans.xml in WEB-INF folder&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px; line-height: 18px;"&gt;We take same example what we discussed in last part&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px; line-height: 18px;"&gt;one interface (Hello) and two implementation(HelloImplOne, HelloImplTwo)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px; line-height: 18px;"&gt;here i marked &lt;u&gt;@Alternative&lt;/u&gt; in both implementation&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', Trebuchet, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;u&gt;Hello&lt;/u&gt; Interface&lt;br /&gt;
&lt;pre class="java" name="code"&gt;package org.ramki.service;

/**
 *
 * @author ramki
 */
public interface Hello {

    String sayHello(String name);
}
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;HelloImplOne&lt;/u&gt; Implementation&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;package org.ramki.service;

/**
 *
 * @author ramki
 */
@Alternative
public class HelloImplOne implements Hello {

    @Override
    public String sayHello(String name) {
        return "Hello, Mr "+name;
    }

}
&lt;/pre&gt;&lt;br /&gt;
&lt;!-- adsense --&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;HelloImplTwo&lt;/u&gt; Implementation&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;package org.ramki.service;

/**
 *
 * @author ramki
 */
@Alternative
public class HelloImplTwo implements Hello {

    @Override
    public String sayHello(String name) {
       return "Hi, "+name;
    }

}
&lt;/pre&gt;&lt;br /&gt;
and go and modify the beans.xml in WEB_INF folder&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;&lt;beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemalocation="http://java.sun.com/xml/ns/javaee
      http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"&gt;

      &lt;alternatives&gt;
             &lt;class&gt;org.ramki.service.HelloImplTwo&lt;/class&gt;
      &lt;/alternatives&gt;
&lt;/beans&gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
In&amp;nbsp;&amp;lt;alternatives&amp;gt; tag in beans.xml we need specify which one need to inject.&lt;br /&gt;
&lt;br /&gt;
See the&amp;nbsp;screen cast&amp;nbsp;for demo&lt;br /&gt;
&lt;br /&gt;
&lt;object height="745" width="960"&gt;&lt;param name="movie" value="http://www.youtube.com/v/_7CMqWV7Ooc?fs=1&amp;amp;hl=en_US&amp;amp;hd=1&amp;amp;color1=0x5d1719&amp;amp;color2=0xcd311b"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/_7CMqWV7Ooc?fs=1&amp;amp;hl=en_US&amp;amp;hd=1&amp;amp;color1=0x5d1719&amp;amp;color2=0xcd311b" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="960" height="745"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS', Trebuchet, sans-serif; line-height: 22px;"&gt;&lt;em style="font-style: normal; font-weight: bold;"&gt;Comments are welcomed&lt;/em&gt;&lt;/span&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=zQhOVl7Rmhs:uCmphUgzVAs:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=zQhOVl7Rmhs:uCmphUgzVAs:63t7Ie-LG7Y"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=63t7Ie-LG7Y" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=zQhOVl7Rmhs:uCmphUgzVAs:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?i=zQhOVl7Rmhs:uCmphUgzVAs:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/ramki/feeds?a=zQhOVl7Rmhs:uCmphUgzVAs:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/ramki/feeds?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/ramki/feeds/~4/zQhOVl7Rmhs" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ramki/feeds/~3/zQhOVl7Rmhs/understanding-cdi-contexts-and.html</link><author>noreply@blogger.com (Rama krishnnan E P)</author><gd:extendedProperty name="commentSource" value="1" /><gd:extendedProperty name="commentModerationMode" value="FILTERED_POSTMOD" /><feedburner:origLink>http://www.ramkitech.com/2010/12/understanding-cdi-contexts-and.html</feedburner:origLink></item></channel></rss>
