<?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:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>ViralPatel.net</title>
	
	<link>http://viralpatel.net/blogs</link>
	<description>Tutorials, Java, J2EE, Struts, AJAX, JavaScript, CSS, Web 2.0, MySQL, Articles</description>
	<lastBuildDate>Sun, 01 Aug 2010 09:44:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/viralpatelnet" /><feedburner:info uri="viralpatelnet" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>viralpatelnet</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Creating Dynamic Web Project using Maven in Eclipse</title>
		<link>http://feedproxy.google.com/~r/viralpatelnet/~3/BMVwpo6ETF0/generate-dynamic-web-project-maven-eclipse-wtp.html</link>
		<comments>http://viralpatel.net/blogs/2010/07/generate-dynamic-web-project-maven-eclipse-wtp.html#comments</comments>
		<pubDate>Wed, 28 Jul 2010 13:41:20 +0000</pubDate>
		<dc:creator>Viral Patel</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[apache maven]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[eclipse plugins]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[maven plugins]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=2096</guid>
		<description><![CDATA[While using Maven as build tool in our project, I found it very difficult to create a Dynamic Web Project which supports Maven dependencies and can execute in Eclipse! I have seen lot of people using Maven just as build tool and for local setup uses jar files in some /lib directory. I wanted to [...]]]></description>
			<content:encoded><![CDATA[<p>While using Maven as build tool in our project, I found it very difficult to create a Dynamic Web Project which supports <a href="http://viralpatel.net/blogs/2009/04/introduction-apache-maven-build-framework-build-automation-tool.html">Maven dependencies</a> and can execute in Eclipse! I have seen lot of people using Maven just as build tool and for local setup uses jar files in some /lib directory. I wanted to remove this dependencies on local /lib for jar files and resolve everything with Maven. My project should be a Dynamic web project with Maven dependencies enabled. </p>
<p>Here is a simple tutorial which you can go through to create Dynamic Web Project having Maven enabled in Eclipse. This project can be used as base project and can be easily converted to most kind of project like Struts based, Spring MVC based etc.</p>
<h2>Required Tools</h2>
<p>For this tutorial, I assume you have following setup in your machine.<br />
1. JDK 1.5 or above (<a rel="nofollow" target="_new" href="http://java.sun.com/javase/downloads/index.jsp">download</a>)<br />
2. Eclipse 3.2 or above (<a rel="nofollow" target="_new" href="http://www.eclipse.org/downloads/">download</a>)<br />
3. Maven 2.0 or above (<a rel="nofollow" target="_new" href="http://maven.apache.org/download.html">download</a>)<br />
4. M2Eclipse Plugin (<a rel="nofollow" target="_new" href="http://m2eclipse.sonatype.org/installing-m2eclipse.html">download</a>)</p>
<h2>Step 1: Create Maven Project in Eclipse</h2>
<p>Create a new project in Eclipse. Goto <strong>File > New > Project.. </strong>and select <strong>Maven Project</strong> from the list. Click Next.<br />
<img src="http://img.viralpatel.net/2010/07/eclipse-maven-new-project.png" alt="eclipse-maven-new-project" title="eclipse-maven-new-project" width="363" height="353" class="aligncenter size-full wp-image-2097" /></p>
<p>Enter <strong>&#8220;MavenWeb&#8221;</strong> as Project name and click Next. On Configuration screen, select <strong>war</strong> in Packaging and also check the checkbox for <strong>src/main/webapp</strong>. </p>
<p><img src="http://img.viralpatel.net/2010/07/new-maven-project.png" alt="new-maven-project" title="new-maven-project" width="361" height="447" class="aligncenter size-full wp-image-2098" /></p>
<p>Once done, click Finish. This will create a Maven project in Eclipse.</p>
<h2>Step 2: Generate Eclipse Project with WTP</h2>
<p>Let us convert the Maven project to Dynamic Web Project for Eclipse. For this we will use following maven command.</p>
<pre class="brush: xml;">
mvn eclipse:eclipse -Dwtpversion=1.5
</pre>
<p>Goto the folder where the new project is created and execute above command.</p>
<pre>
C:\Workspace\Test\MavenWeb>mvn eclipse:eclipse -Dwtpversion=1.5

[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'eclipse'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - MavenWeb:MavenWeb:war:0.0.1-SNAPSHOT
[INFO]    task-segment: [eclipse:eclipse]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing eclipse:eclipse
[INFO] No goals needed for project - skipping
[INFO] [eclipse:eclipse]
[INFO] Adding support for WTP version 1.5.
[INFO] Using Eclipse Workspace: C:\Workspace\Test
[INFO] no substring wtp server match.
[INFO] Using as WTP server : Apache Tomcat v5.5
[INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER
[INFO] Not writing settings - defaults suffice
[INFO] Wrote Eclipse project for "MavenWeb" to C:\Workspace\Test\MavenWeb.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4 seconds
[INFO] Finished at: Wed Jul 28 13:55:09 CEST 2010
[INFO] Final Memory: 7M/30M
[INFO] ------------------------------------------------------------------------
</pre>
<p>That&#8217;s it. We just created Dynamic Web Project from Maven project. Now refresh the project in Eclipse.</p>
<h2>Step 3: Change Project Facet</h2>
<p>The above step by default set the project facet to JDK 1.4. We need to modify this and set project facet to JDK 5. Right click on MavenWeb project and select Properties (shortcut: Alt+Enter). From the Properties dialog box, select Project Facets. Now click on &#8220;Modify Project&#8230;&#8221; button and change the project facet to Java 5.0<br />
<img src="http://img.viralpatel.net/2010/07/project-facet-maven-eclipse.png" alt="project-facet-maven-eclipse" title="project-facet-maven-eclipse" width="368" height="432" class="aligncenter size-full wp-image-2100" /></p>
<h2>Step 4: Setting Build Path</h2>
<p>We need to specify the Maven jar dependencies in Java Build Path of our MavenWeb project. Open Properties.. dialog box (Alt+Enter) and select <strong>Java Build Path</strong>. Click &#8220;Add Library..&#8221; button and select <strong>&#8220;Maven Managed Dependencies&#8221;</strong> and click Finish.<br />
<img src="http://img.viralpatel.net/2010/07/maven-eclipse-build-path.png" alt="maven-eclipse-build-path" title="maven-eclipse-build-path" width="598" height="447" class="aligncenter size-full wp-image-2099" /></p>
<h2>Step 5: Hello World Servlet</h2>
<p>Our dynamic web project with maven support is done now. Let us add a small Hello World servlet to this project and see how it works.</p>
<p>Open pom.xml from root folder and copy following content into it.</p>
<p><em>File: pom.xml</em></p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project&gt;
	&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
	&lt;groupId&gt;MavenWeb&lt;/groupId&gt;
	&lt;artifactId&gt;MavenWeb&lt;/artifactId&gt;
	&lt;packaging&gt;war&lt;/packaging&gt;
	&lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
	&lt;description&gt;&lt;/description&gt;
	&lt;build&gt;
		&lt;plugins&gt;
			&lt;plugin&gt;
				&lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
				&lt;version&gt;2.0&lt;/version&gt;
			&lt;/plugin&gt;
		&lt;/plugins&gt;
	&lt;/build&gt;
	&lt;dependencies&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;javax.servlet&lt;/groupId&gt;
			&lt;artifactId&gt;servlet-api&lt;/artifactId&gt;
			&lt;version&gt;2.5&lt;/version&gt;
		&lt;/dependency&gt;
	&lt;/dependencies&gt;
&lt;/project&gt;
</pre>
<p>Also create a servlet file HelloWorldServlet.java. We will add this servlet in <strong>net.viralpatel.maven</strong> package.</p>
<p><em>File: /src/main/java/net/viralpatel/maven/HelloWorldServlet.java</em></p>
<pre class="brush: java;">
package net.viralpatel.maven;

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

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloWorldServlet extends HttpServlet {

	private static final long serialVersionUID = 1031422249396784970L;

	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		resp.setContentType(&quot;text/html&quot;);

		PrintWriter out = resp.getWriter();
		out.print(&quot;Hello World from Servlet&quot;);
		out.flush();
		out.close();
	}
}
</pre>
<p>Once the servlet is created, let us configure this in web.xml. Note that in our maven project no web.xml is present. We will create one at /src/main/webapp/WEB-INF/ location.</p>
<p><em>File: /src/main/webapp/WEB-INF/web.xml</em></p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;web-app xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot;
	xmlns:web=&quot;http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot;
	xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot;
	id=&quot;WebApp_ID&quot; version=&quot;2.5&quot;&gt;
	&lt;display-name&gt;HelloWorldServlet&lt;/display-name&gt;
	&lt;welcome-file-list&gt;
		&lt;welcome-file&gt;hello-world&lt;/welcome-file&gt;
	&lt;/welcome-file-list&gt;

	&lt;servlet&gt;
		&lt;servlet-name&gt;HelloWorldServlet&lt;/servlet-name&gt;
		&lt;servlet-class&gt;
			net.viralpatel.maven.HelloWorldServlet
		&lt;/servlet-class&gt;
		&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
	&lt;/servlet&gt;
	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;HelloWorldServlet&lt;/servlet-name&gt;
		&lt;url-pattern&gt;/hello-world&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;
&lt;/web-app&gt;
</pre>
<h2>That&#8217;s All Folks</h2>
<p>Our dynamic web project with Maven support in Eclipse is completed. Run the web project in eclipse (Alt+Shirt+X, R)<br />
<img src="http://img.viralpatel.net/2010/07/hello-world-maven-eclipse-web-project.png" alt="hello-world-maven-eclipse-web-project" title="hello-world-maven-eclipse-web-project" width="320" height="230" class="aligncenter size-full wp-image-2101" /></p>
<h2>Download Source</h2>
<p><a href="http://viralpatel.net/blogs/download/j2ee/maven/MavenWeb.zip">Click here to download the source code (7.0 kb)</a></p>
<div style="background-color: rgb(255, 241, 168); padding: 3px;" id="relatedpost"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2009/04/introduction-apache-maven-build-framework-build-automation-tool.html" title="Introduction to Apache Maven: A build framework &#038; build automation tool">Introduction to Apache Maven: A build framework &#038; build automation tool</a></li><li><a href="http://viralpatel.net/blogs/2009/04/google-android-adt-sdk-and-eclipse-ide-integration-on-linux.html" title="Google Android ADT, SDK and Eclipse IDE integration on Linux ">Google Android ADT, SDK and Eclipse IDE integration on Linux </a></li><li><a href="http://viralpatel.net/blogs/2010/06/eclipse-tip-add-code-template-eclipse.html" title="Eclipse Tip: Add your own Code Template in Eclipse">Eclipse Tip: Add your own Code Template in Eclipse</a></li><li><a href="http://viralpatel.net/blogs/2010/02/hide-closed-projects-eclipse-project-explorer-view.html" title="Eclipse Tip: Hide Closed Projects in Eclipse Project Explorer View">Eclipse Tip: Hide Closed Projects in Eclipse Project Explorer View</a></li><li><a href="http://viralpatel.net/blogs/2009/10/eclipse-workspace-in-use-or-cannot-be-created-error.html" title="Eclipse: Workspace in use or cannot be created Error">Eclipse: Workspace in use or cannot be created Error</a></li><li><a href="http://viralpatel.net/blogs/2009/10/setting-tomcat-heap-size-jvm-heap-eclipse.html" title="Setting Tomcat Heap Size (JVM Heap) in Eclipse">Setting Tomcat Heap Size (JVM Heap) in Eclipse</a></li><li><a href="http://viralpatel.net/blogs/2009/09/database-connection-pooling-tomcat-eclipse-db.html" title="Database Connection Pooling in Tomcat using Eclipse">Database Connection Pooling in Tomcat using Eclipse</a></li><li><a href="http://viralpatel.net/blogs/2009/07/20-very-useful-eclipse-ide-shortcuts-for-developers.html" title="20 very useful Eclipse IDE Shortcuts for Developers">20 very useful Eclipse IDE Shortcuts for Developers</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2010/07/generate-dynamic-web-project-maven-eclipse-wtp.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2010/07/generate-dynamic-web-project-maven-eclipse-wtp.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2010/07/generate-dynamic-web-project-maven-eclipse-wtp.html&amp;title=Creating Dynamic Web Project using Maven in Eclipse&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2010/07/generate-dynamic-web-project-maven-eclipse-wtp.html&amp;title=Creating Dynamic Web Project using Maven in Eclipse" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2010/07/generate-dynamic-web-project-maven-eclipse-wtp.html&amp;title=Creating Dynamic Web Project using Maven in Eclipse" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2010/07/generate-dynamic-web-project-maven-eclipse-wtp.html&amp;title=Creating Dynamic Web Project using Maven in Eclipse" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>
<p><a href="http://feedads.g.doubleclick.net/~a/OO0Ysf_k7tsKBTgxy5f7hVSIThI/0/da"><img src="http://feedads.g.doubleclick.net/~a/OO0Ysf_k7tsKBTgxy5f7hVSIThI/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/OO0Ysf_k7tsKBTgxy5f7hVSIThI/1/da"><img src="http://feedads.g.doubleclick.net/~a/OO0Ysf_k7tsKBTgxy5f7hVSIThI/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=BMVwpo6ETF0:aWtq8JqAlZw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=BMVwpo6ETF0:aWtq8JqAlZw:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=BMVwpo6ETF0:aWtq8JqAlZw:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=BMVwpo6ETF0:aWtq8JqAlZw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=BMVwpo6ETF0:aWtq8JqAlZw:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=BMVwpo6ETF0:aWtq8JqAlZw:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=BMVwpo6ETF0:aWtq8JqAlZw:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=BMVwpo6ETF0:aWtq8JqAlZw:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=BMVwpo6ETF0:aWtq8JqAlZw:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2010/07/generate-dynamic-web-project-maven-eclipse-wtp.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://viralpatel.net/blogs/2010/07/generate-dynamic-web-project-maven-eclipse-wtp.html</feedburner:origLink></item>
		<item>
		<title>Spring 3 MVC: Internationalization &amp; Localization Tutorial with Example</title>
		<link>http://feedproxy.google.com/~r/viralpatelnet/~3/mNbJpdqAT9U/spring-3-mvc-internationalization-i18n-localization-tutorial-example.html</link>
		<comments>http://viralpatel.net/blogs/2010/07/spring-3-mvc-internationalization-i18n-localization-tutorial-example.html#comments</comments>
		<pubDate>Wed, 14 Jul 2010 13:20:17 +0000</pubDate>
		<dc:creator>Viral Patel</dc:creator>
				<category><![CDATA[Spring]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[internationalization]]></category>
		<category><![CDATA[spring mvc]]></category>
		<category><![CDATA[spring-3-mvc-series]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=2088</guid>
		<description><![CDATA[Welcome to Part 5 for Spring 3.0 MVC Series. In previous article we saw how to configure Tiles framework with Spring 3 MVC application. We used org.springframework.web.servlet.view.tiles2.TilesConfigurer class in bean definition to define the tiles configuration file. This divided our HelloWorld Spring MVC application in sections such as header, footer etc. In this part we [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to Part 5 for <strong>Spring 3.0 MVC Series</strong>. In <a href="http://viralpatel.net/blogs/2010/07/spring-3-mvc-tiles-plugin-tutorial-example-eclipse.html">previous article</a> we saw how to configure Tiles framework with Spring 3 MVC application. We used <code>org.springframework.web.servlet.view.tiles2.TilesConfigurer</code> class in bean definition to define the tiles configuration file. This divided our HelloWorld Spring MVC application in sections such as header, footer etc.</p>
<p>In this part we will discuss about Internationalization (I18N) and Localization (L10N) in Spring 3.0 MVC. We will add i18n support followed by l10n to our HelloWorld Spring application that we created in previous tutorials in this series. I strongly recommend you to go through previous articles and download the source code of our sample application.</p>
<style type="text/css">#spring { color:#222222; width: 98%; background-color: #EEFF99; padding:5px; -moz-border-radius: 10px; -webkit-border-radius: 10px; }#spring h3 { font-size: 18px; text-decoration:underline; }#spring ul { list-style:none; }#spring ul li { padding:3px; }</style><div id="spring"><h3>Spring 3.0 MVC Series</h3><ul>	<li><a href="http://viralpatel.net/blogs/2010/06/tutorial-spring-3-mvc-introduction-spring-mvc-framework.html">Part 1: Introduction to Spring 3.0 MVC framework</a></li>	<li><a href="http://viralpatel.net/blogs/2010/06/spring-3-mvc-create-hello-world-application-spring-3-mvc.html">Part 2: Create Hello World Application in Spring 3.0 MVC</a></li>	<li><a href="http://viralpatel.net/blogs/2010/07/spring-3-mvc-handling-forms.html">Part 3: Handling Forms in Spring 3.0 MVC</a></li>	<li><a href="http://viralpatel.net/blogs/2010/07/spring-3-mvc-tiles-plugin-tutorial-example-eclipse.html">Part 4: Spring 3 MVC Tiles Plugin Tutorial with Example in Eclipse</a></li>	<li><a href="http://viralpatel.net/blogs/2010/07/spring-3-mvc-internationalization-i18n-localization-tutorial-example.html">Part 5: Spring 3 MVC Internationalization & Localization Tutorial with Example in Eclipse</a></li></ul></div>
<h2>What is i18n and L10n?</h2>
<p>In computing, internationalization and localization are means of adapting computer software to different languages and regional differences. Internationalization is the process of designing a software application so that it can be adapted to various languages and regions without engineering changes. Localization is the process of adapting internationalized software for a specific region or language by adding locale-specific components and translating text.</p>
<p>The terms are frequently abbreviated to the numeronyms  i18n (where 18 stands for the number of letters between the first i and last n in internationalization) and L10n respectively, due to the length of the words. The capital L in L10n helps to distinguish it from the lowercase i in i18n.</p>
<h2>Our Goal</h2>
<p>Our goal is to add Internationalization and Localization support to our Spring MVC application. Once finished our app will look like.<br />
<img src="http://img.viralpatel.net/2010/07/contact-manager-screen-de.png" alt="contact-manager-screen-de" title="contact-manager-screen-de" width="324" height="356" class="aligncenter size-full wp-image-2089" /></p>
<p>We will add two languages support to our application: English and German. Depending on the locale setting of users browser, the appropriate language will be selected. Also user will be able to select the language from top-right corner of the application.</p>
<h2>Message Resouces File</h2>
<p>We will create two properties file which will contain all the messages to be displayed in the application. These files are kept in a source folder called &#8220;resources&#8221;. Create a source folder in your project by <strong>Right click on Project name &gt; New &gt; Source Folder</strong> and name it <strong>resources</strong>.<br />
<img src="http://img.viralpatel.net/2010/07/message-resources-properties-spring-mvc.png" alt="message-resources-properties-spring-mvc" title="message-resources-properties-spring-mvc" width="217" height="119" class="aligncenter size-full wp-image-2090" /></p>
<p>Create two files <code>messages_en.properties</code> and <code>messages_de.properties</code> in this folder and copy following content into it.</p>
<p><em>File: resources/messages_en.properties</em></p>
<pre class="brush: xml;">
label.firstname=First Name
label.lastname=Last Name
label.email=Email
label.telephone=Telephone
label.addcontact=Add Contact

label.menu=Menu
label.title=Contact Manager

label.footer=&amp;copy; ViralPatel.net
</pre>
<p><em>File: resources/messages_de.properties</em></p>
<pre class="brush: xml;">
label.firstname=Vorname
label.lastname=Familiename
label.email=Email
label.telephone=Telefon
label.addcontact=Addieren Kontakt 

label.title=Kontakt Manager
label.menu=Men&amp;#252;

label.footer=&amp;copy; ViralPatel.net
</pre>
<h2>Configuring Internationalization (i18n) / Localization (L10n) in Spring MVC</h2>
<p>Now we have created message resource properties for our application. We need to declare these files in spring configuration file. We will use class <code>org.springframework.context.support.ReloadableResourceBundleMessageSource</code> to define the message resources.</p>
<p>Also, note that we will provide a feature where user will be able to select language for the application. This is implemented by using <code>org.springframework.web.servlet.i18n.LocaleChangeInterceptor</code> class. The LocaleChangeInterceptor class will intercept any changes in the locale. These changes are then saved in cookies for future request. <code>org.springframework.web.servlet.i18n.CookieLocaleResolver</code> class will be used to store the locale changes in cookies.</p>
<p>Add following code in the spring-servlet.xml file.</p>
<p><em>File:WebContent/WEB-INF/spring-servlet.xml</em></p>
<pre class="brush: xml;">
	&lt;bean id=&quot;messageSource&quot;
		class=&quot;org.springframework.context.support.ReloadableResourceBundleMessageSource&quot;&gt;
		&lt;property name=&quot;basename&quot; value=&quot;classpath:messages&quot; /&gt;
		&lt;property name=&quot;defaultEncoding&quot; value=&quot;UTF-8&quot;/&gt;
	&lt;/bean&gt;

	&lt;bean id=&quot;localeChangeInterceptor&quot;
		class=&quot;org.springframework.web.servlet.i18n.LocaleChangeInterceptor&quot;&gt;
		&lt;property name=&quot;paramName&quot; value=&quot;lang&quot; /&gt;
	&lt;/bean&gt;

	&lt;bean id=&quot;localeResolver&quot;
		class=&quot;org.springframework.web.servlet.i18n.CookieLocaleResolver&quot;&gt;
		&lt;property name=&quot;defaultLocale&quot; value=&quot;en&quot;/&gt;
	&lt;/bean&gt;

	&lt;bean id=&quot;handlerMapping&quot;
		class=&quot;org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping&quot;&gt;
		&lt;property name=&quot;interceptors&quot;&gt;
			&lt;ref bean=&quot;localeChangeInterceptor&quot; /&gt;
		&lt;/property&gt;
	&lt;/bean&gt;
</pre>
<p>Note that in above configuration we have defined basename property in messageSource bean to classpath:messages. By this, spring will identify that the message resource  message_<locale> will be used in this application.</p>
<h2>Change the View &#8211; The JSPs</h2>
<p>Now as we have created two message resources files and configured it in Spring MVC, we will use these messages in the JSP files. Open all the JSP files of our demo application and update with following code.</p>
<p><em>File:WebContent/WEB-INF/jsp/header.jsp</em></p>
<pre class="brush: xml;">
&lt;%@taglib uri=&quot;http://www.springframework.org/tags&quot; prefix=&quot;spring&quot;%&gt;

&lt;h3&gt;&lt;spring:message code=&quot;label.title&quot;/&gt;&lt;/h3&gt;

&lt;span style=&quot;float: right&quot;&gt;
	&lt;a href=&quot;?lang=en&quot;&gt;en&lt;/a&gt;
	|
	&lt;a href=&quot;?lang=de&quot;&gt;de&lt;/a&gt;
&lt;/span&gt;
</pre>
<p><em>File:WebContent/WEB-INF/jsp/menu.jsp</em></p>
<pre class="brush: xml;">
&lt;%@taglib uri=&quot;http://www.springframework.org/tags&quot; prefix=&quot;spring&quot;%&gt;

&lt;p&gt;&lt;spring:message code=&quot;label.menu&quot;/&gt;&lt;/p&gt;
</pre>
<p><em>File:WebContent/WEB-INF/jsp/footer.jsp</em></p>
<pre class="brush: xml;">
&lt;%@taglib uri=&quot;http://www.springframework.org/tags&quot; prefix=&quot;spring&quot;%&gt;

&lt;spring:message code=&quot;label.footer&quot;/&gt;
</pre>
<p><em>File:WebContent/WEB-INF/jsp/contact.jsp</em></p>
<pre class="brush: xml;">
&lt;%@taglib uri=&quot;http://www.springframework.org/tags&quot; prefix=&quot;spring&quot;%&gt;
&lt;%@taglib uri=&quot;http://www.springframework.org/tags/form&quot; prefix=&quot;form&quot;%&gt;
&lt;html&gt;
&lt;head&gt;
	&lt;title&gt;Spring 3 MVC Series - Contact Manager&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;form:form method=&quot;post&quot; action=&quot;addContact.html&quot;&gt;

	&lt;table&gt;
	&lt;tr&gt;
		&lt;td&gt;&lt;form:label path=&quot;firstname&quot;&gt;&lt;spring:message code=&quot;label.firstname&quot;/&gt;&lt;/form:label&gt;&lt;/td&gt;
		&lt;td&gt;&lt;form:input path=&quot;firstname&quot; /&gt;&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td&gt;&lt;form:label path=&quot;lastname&quot;&gt;&lt;spring:message code=&quot;label.lastname&quot;/&gt;&lt;/form:label&gt;&lt;/td&gt;
		&lt;td&gt;&lt;form:input path=&quot;lastname&quot; /&gt;&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td&gt;&lt;form:label path=&quot;lastname&quot;&gt;&lt;spring:message code=&quot;label.email&quot;/&gt;&lt;/form:label&gt;&lt;/td&gt;
		&lt;td&gt;&lt;form:input path=&quot;email&quot; /&gt;&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td&gt;&lt;form:label path=&quot;lastname&quot;&gt;&lt;spring:message code=&quot;label.telephone&quot;/&gt;&lt;/form:label&gt;&lt;/td&gt;
		&lt;td&gt;&lt;form:input path=&quot;telephone&quot; /&gt;&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td colspan=&quot;2&quot;&gt;
			&lt;input type=&quot;submit&quot; value=&quot;&lt;spring:message code=&quot;label.addcontact&quot;/&gt;&quot;/&gt;
		&lt;/td&gt;
	&lt;/tr&gt;
&lt;/table&gt;	

&lt;/form:form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Note that in above JSP, we used <code>&lt;spring:message&gt;</code> tag to display the message from resource bundle.</p>
<p>One thing that we must note here is that in header.jsp file, we have specified two links to select language. The link sets a request parameter <strong>?lang=<language code></strong> when user click on this link. Note that spring identifies this request parameter by using <code>LocaleChangeInterceptor</code> interceptor and change the local accordingly. Also note that while configuring <code>LocaleChangeInterceptor</code> in spring-servlet.xml file, we have specified property &#8220;paramName&#8221; with value &#8220;lang&#8221;</p>
<pre class="brush: xml;">
&lt;property name=&quot;paramName&quot; value=&quot;lang&quot; /&gt;
</pre>
<p>Thus the Spring framework will look for a parameter called &#8220;lang&#8221; from request.</p>
<h2>That&#8217;s All Folks</h2>
<p>That&#8217;s pretty much it :) We just added Internationalization and Localization support to our demo Spring 3.0 MVC application. All you have to do is just execute the app in Eclipse. Press Alt + Shift + X, R.</p>
<p><img src="http://img.viralpatel.net/2010/07/contact-manager-screen-en.png" alt="contact-manager-screen-en" title="contact-manager-screen-en" width="320" height="355" class="aligncenter size-full wp-image-2091" /></p>
<p><img src="http://img.viralpatel.net/2010/07/contact-manager-screen-de.png" alt="contact-manager-screen-de" title="contact-manager-screen-de" width="324" height="356" class="aligncenter size-full wp-image-2089" /></p>
<h2>Download Source Code</h2>
<p><a href="http://viralpatel.net/blogs/download/spring/spring-3-mvc-series/Spring3MVC-part5.zip">Click here to download Source Code (10.2kb)</a></p>
<h2>Moving On</h2>
<p>Today we saw how to add Internationalization i18n and Localization L10n support to Spring 3.0 based web application. We used <code>LocaleChangeInterceptor</code> to intercept the change in locale and <code>ReloadableResourceBundleMessageSource</code> class to add message resources properties. In the next part we will discuss Themes in Spring MVC and how to implement it. I hope you liked this article. Feel free to post your queries and comments in comment section.</p>
<div style="background-color: rgb(255, 241, 168); padding: 3px;" id="relatedpost"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2010/07/spring-3-mvc-tiles-plugin-tutorial-example-eclipse.html" title="Spring 3 MVC: Tiles Plugin Tutorial with Example in Eclipse">Spring 3 MVC: Tiles Plugin Tutorial with Example in Eclipse</a></li><li><a href="http://viralpatel.net/blogs/2010/07/spring-3-mvc-handling-forms.html" title="Spring 3 MVC: Handling Forms in Spring 3.0 MVC">Spring 3 MVC: Handling Forms in Spring 3.0 MVC</a></li><li><a href="http://viralpatel.net/blogs/2010/06/spring-3-mvc-create-hello-world-application-spring-3-mvc.html" title="Spring 3 MVC: Create Hello World application in Spring 3.0 MVC">Spring 3 MVC: Create Hello World application in Spring 3.0 MVC</a></li><li><a href="http://viralpatel.net/blogs/2010/06/tutorial-spring-3-mvc-introduction-spring-mvc-framework.html" title="Spring 3 MVC – Introduction to Spring 3 MVC Framework">Spring 3 MVC – Introduction to Spring 3 MVC Framework</a></li><li><a href="http://viralpatel.net/blogs/2010/01/configuring-mdp-and-controlling-it-with-and-without-jmx.html" title="Configuring MDP and Controlling it With and Without JMX">Configuring MDP and Controlling it With and Without JMX</a></li><li><a href="http://viralpatel.net/blogs/2008/12/tutorial-struts-spring-framework-example-in-eclipse.html" title="Tutorial:Struts Spring framework example in Eclipse.">Tutorial:Struts Spring framework example in Eclipse.</a></li><li><a href="http://viralpatel.net/blogs/2008/11/struts-internationalization-i18n.html" title="Struts Internationalization (I18N)">Struts Internationalization (I18N)</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2010/07/spring-3-mvc-internationalization-i18n-localization-tutorial-example.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2010/07/spring-3-mvc-internationalization-i18n-localization-tutorial-example.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2010/07/spring-3-mvc-internationalization-i18n-localization-tutorial-example.html&amp;title=Spring 3 MVC: Internationalization &#038; Localization Tutorial with Example&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2010/07/spring-3-mvc-internationalization-i18n-localization-tutorial-example.html&amp;title=Spring 3 MVC: Internationalization &#038; Localization Tutorial with Example" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2010/07/spring-3-mvc-internationalization-i18n-localization-tutorial-example.html&amp;title=Spring 3 MVC: Internationalization &#038; Localization Tutorial with Example" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2010/07/spring-3-mvc-internationalization-i18n-localization-tutorial-example.html&amp;title=Spring 3 MVC: Internationalization &#038; Localization Tutorial with Example" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>
<p><a href="http://feedads.g.doubleclick.net/~a/ozr_jyjODdcXHOlawNudP0xCN_A/0/da"><img src="http://feedads.g.doubleclick.net/~a/ozr_jyjODdcXHOlawNudP0xCN_A/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/ozr_jyjODdcXHOlawNudP0xCN_A/1/da"><img src="http://feedads.g.doubleclick.net/~a/ozr_jyjODdcXHOlawNudP0xCN_A/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=mNbJpdqAT9U:LVUofn92kxw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=mNbJpdqAT9U:LVUofn92kxw:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=mNbJpdqAT9U:LVUofn92kxw:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=mNbJpdqAT9U:LVUofn92kxw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=mNbJpdqAT9U:LVUofn92kxw:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=mNbJpdqAT9U:LVUofn92kxw:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=mNbJpdqAT9U:LVUofn92kxw:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=mNbJpdqAT9U:LVUofn92kxw:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=mNbJpdqAT9U:LVUofn92kxw:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2010/07/spring-3-mvc-internationalization-i18n-localization-tutorial-example.html/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		<feedburner:origLink>http://viralpatel.net/blogs/2010/07/spring-3-mvc-internationalization-i18n-localization-tutorial-example.html</feedburner:origLink></item>
		<item>
		<title>Calculate Free Disk Space in Java using Apache Commons IO</title>
		<link>http://feedproxy.google.com/~r/viralpatelnet/~3/Loe2kOBwwlo/java-calculate-free-disk-space-java-apache-commons-io.html</link>
		<comments>http://viralpatel.net/blogs/2010/07/java-calculate-free-disk-space-java-apache-commons-io.html#comments</comments>
		<pubDate>Mon, 12 Jul 2010 15:54:50 +0000</pubDate>
		<dc:creator>Viral Patel</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[java code]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=2087</guid>
		<description><![CDATA[As a Java developer, lot of times I have to play around with file system. Sometimes I have to copy files/directories from one location to another; sometimes have to process certain files depending on certain pattern. In one of my test program, I wanted to calculate available disk space using Java. Lot of code snippets [...]]]></description>
			<content:encoded><![CDATA[<p><img alt="java logo" src="http://viralpatel.net/blogs/wp-content/uploads/java-logo2.gif" title="java logo" class="alignright" width="152" height="168" />As a Java developer, lot of times I have to play around with file system. Sometimes I have to copy files/directories from one location to another; sometimes have to process certain files depending on certain pattern. In one of my test program, I wanted to calculate available disk space using Java. Lot of code snippets are available for this task. I liked the one using Apache Commons IO library.</p>
<p>Here is a simple trick for Java developers to calculate free diskspace. We have used Apache Commons IO library to calculate this.</p>
<p>Apache Commons IO library contains a class <code>org.apache.commons.io.FileSystemUtils</code> which can be used to calculate the free disk space in any system. Let us see the Java code for this.</p>
<pre class="brush: java;">
package net.viralpatel.java;

import java.io.IOException;

import org.apache.commons.io.FileSystemUtils;

public class DiskSpace {
	public static void main(String[] args) {
		try {

			//calculate free disk space
			double freeDiskSpace = FileSystemUtils.freeSpaceKb(&quot;C:&quot;); 

			//convert the number into gigabyte
			double freeDiskSpaceGB = freeDiskSpace / 1024 / 1024;

			System.out.println(&quot;Free Disk Space (GB):&quot; + freeDiskSpaceGB);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
</pre>
<p><strong>Output:</strong></p>
<pre>
Free Disk Space (GB): 40.145268
</pre>
<p>In above code we used <code>FileSystemUtils.freeSpaceKb( )</code> method to get the free space in kilo byte. This method invokes the command line to calculate the free disk space. You may want to call this method in following way to get free disk space in Windows and Linux.</p>
<pre class="brush: java;">
 FileSystemUtils.freeSpaceKb(&quot;C:&quot;);       // Windows
 FileSystemUtils.freeSpaceKb(&quot;/volume&quot;);  // *nix
 </pre>
<p>The free space is calculated via the command line. It uses <strong>&#8216;dir /-c&#8217;</strong> on Windows, <strong>&#8216;df -kP&#8217;</strong> on AIX/HP-UX and &#8216;<strong>df -k&#8217;</strong> on other Unix.</p>
<p>In order to work, you must be running Windows, or have a implementation of Unix df that supports GNU format when passed -k (or -kP). If you are going to rely on this code, please check that it works on your OS by running some simple tests to compare the command line with the output from this class. </p>
<div style="background-color: rgb(255, 241, 168); padding: 3px;" id="relatedpost"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2009/06/convert-arraylist-to-arrays-in-java.html" title="Convert ArrayList to Arrays in Java">Convert ArrayList to Arrays in Java</a></li><li><a href="http://viralpatel.net/blogs/2010/07/java-tip-how-to-sort-array-in-java-java-util-arrays.html" title="Java Tip: How to Sort Arrays in Java using java.util.Arrays class">Java Tip: How to Sort Arrays in Java using java.util.Arrays class</a></li><li><a href="http://viralpatel.net/blogs/2009/07/static-import-java-example-tutorial.html" title="Static Import in Java: New way to Import things in Java!">Static Import in Java: New way to Import things in Java!</a></li><li><a href="http://viralpatel.net/blogs/2009/06/double-brace-initialization-in-java.html" title="Double Brace Initialization in Java!">Double Brace Initialization in Java!</a></li><li><a href="http://viralpatel.net/blogs/2009/05/how-to-execute-command-prompt-command-view-output-java.html" title="How to execute a command prompt command &#038; view output in Java">How to execute a command prompt command &#038; view output in Java</a></li><li><a href="http://viralpatel.net/blogs/2009/05/inspect-your-code-in-eclipse-using-eclipse-scrapbook-feature.html" title="Inspect your code in Eclipse using Eclipse Scrapbook feature">Inspect your code in Eclipse using Eclipse Scrapbook feature</a></li><li><a href="http://viralpatel.net/blogs/2009/05/getting-jvm-heap-size-used-memory-total-memory-using-java-runtime.html" title="Getting JVM heap size, used memory, total memory using Java Runtime">Getting JVM heap size, used memory, total memory using Java Runtime</a></li><li><a href="http://viralpatel.net/blogs/2009/05/varargs-in-java-variable-argument-method-in-java-5.html" title="Varargs in Java: Variable argument method in Java 5">Varargs in Java: Variable argument method in Java 5</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2010/07/java-calculate-free-disk-space-java-apache-commons-io.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2010/07/java-calculate-free-disk-space-java-apache-commons-io.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2010/07/java-calculate-free-disk-space-java-apache-commons-io.html&amp;title=Calculate Free Disk Space in Java using Apache Commons IO&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2010/07/java-calculate-free-disk-space-java-apache-commons-io.html&amp;title=Calculate Free Disk Space in Java using Apache Commons IO" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2010/07/java-calculate-free-disk-space-java-apache-commons-io.html&amp;title=Calculate Free Disk Space in Java using Apache Commons IO" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2010/07/java-calculate-free-disk-space-java-apache-commons-io.html&amp;title=Calculate Free Disk Space in Java using Apache Commons IO" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>
<p><a href="http://feedads.g.doubleclick.net/~a/bdO3nYJ3b3zGjBpIoTnFM6Mi86s/0/da"><img src="http://feedads.g.doubleclick.net/~a/bdO3nYJ3b3zGjBpIoTnFM6Mi86s/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/bdO3nYJ3b3zGjBpIoTnFM6Mi86s/1/da"><img src="http://feedads.g.doubleclick.net/~a/bdO3nYJ3b3zGjBpIoTnFM6Mi86s/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=Loe2kOBwwlo:S2fYt4dl7xE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=Loe2kOBwwlo:S2fYt4dl7xE:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=Loe2kOBwwlo:S2fYt4dl7xE:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=Loe2kOBwwlo:S2fYt4dl7xE:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=Loe2kOBwwlo:S2fYt4dl7xE:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=Loe2kOBwwlo:S2fYt4dl7xE:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=Loe2kOBwwlo:S2fYt4dl7xE:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=Loe2kOBwwlo:S2fYt4dl7xE:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=Loe2kOBwwlo:S2fYt4dl7xE:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2010/07/java-calculate-free-disk-space-java-apache-commons-io.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://viralpatel.net/blogs/2010/07/java-calculate-free-disk-space-java-apache-commons-io.html</feedburner:origLink></item>
		<item>
		<title>Java Tip: How to Sort Arrays in Java using java.util.Arrays class</title>
		<link>http://feedproxy.google.com/~r/viralpatelnet/~3/42Nqe6fgT0U/java-tip-how-to-sort-array-in-java-java-util-arrays.html</link>
		<comments>http://viralpatel.net/blogs/2010/07/java-tip-how-to-sort-array-in-java-java-util-arrays.html#comments</comments>
		<pubDate>Fri, 09 Jul 2010 04:00:45 +0000</pubDate>
		<dc:creator>Viral Patel</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[arraylists]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=2085</guid>
		<description><![CDATA[Here is a small but very useful tip that every Java programmer should be aware of. Have you ever tried sorting arrays in Java? Well, java.util.Arrays class has built in method to make your job easy. You can use following method to sort any array in Java. import java.util.Arrays; ... ... Arrays.sort (int []) Arrays.sort [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a small but very useful tip that every Java programmer should be aware of. Have you ever tried sorting arrays in Java? Well, <code>java.util.Arrays</code> class has built in method to make your job easy. You can use following method to sort any array in Java.</p>
<pre class="brush: java;">
import java.util.Arrays;
...
...
Arrays.sort (int [])
Arrays.sort (String [])
Arrays.sort (float [])
Arrays.sort (double [])
Arrays.sort (long [])
Arrays.sort (Object [])
...
</pre>
<p>Let us check an example were we will sort an array of String in ascending as well as descending order. Here is a string array we defined in Java.</p>
<pre class="brush: java;">
String [] stringArray = {&quot;ab&quot;, &quot;aB&quot;, &quot;c&quot;, &quot;0&quot;, &quot;2&quot;, &quot;1Ad&quot;, &quot;a10&quot;};

System.out.println(&quot;****** Unsorted String Array *******&quot;);
for (String str : stringArray) {
	System.out.println(str);
}
</pre>
<p><strong>Output:</strong></p>
<pre>
****** unsorted string *******
ab
aB
c
0
2
1Ad
a10
</pre>
<p>In above code we simple define an array of String and printed its value. Now lets sort this array in ascending order using <code>Arrays.sort()</code> method.</p>
<h3>Sort in Ascending Order</h3>
<pre class="brush: java;">
//Sort array in ascending order
Arrays.sort(stringArray);

System.out.println(&quot;****** Sorted String Array *******&quot;);
for (String str : stringArray) {
	System.out.println(str);
}
</pre>
<p><strong>Output:</strong></p>
<pre>
****** Sorted String Array *******
0
1Ad
2
a10
aB
ab
c
</pre>
<p>Note that we just sorted an array of String in ascending order using sort method. Wasn&#8217;t it easy.. </p>
<h3>Sort in Descending Order</h3>
<p>Now lets try to sort the array in reverse order. For this we will use a different signature of sort method. </p>
<pre class="brush: java;">
Arrays.sort (Object [], Comparator)
</pre>
<p>Following is the code to sort array in reverse order.</p>
<pre class="brush: java;">
//Sort array in reverse order
Arrays.sort(stringArray, Collections.reverseOrder());

System.out.println(&quot;****** Reverse Sorted String Array *******&quot;);
for (String str : stringArray) {
	System.out.println(str);
}
</pre>
<p><strong>Output:</strong></p>
<pre>
****** Reverse Sorted String Array *******
c
ab
aB
a10
2
1Ad
0
</pre>
<h3>Selective Sorting</h3>
<p>Using Arrays.sort() method it is possible to sort an array selectively. i.e. if you want a subpart of array to be sorted, that is possible using following method.</p>
<pre class="brush: java;">
Arrays.sort (Object [], int startIndex, int endIndex)
</pre>
<p>In following code we are sorting the array starting from index 3 till the end. </p>
<pre class="brush: java;">
//Sorting array starting from index 3 till 6
Arrays.sort(stringArray, 3, 6);

System.out.println(&quot;****** Selective Sort String Array *******&quot;);
for (String str : stringArray) {
	System.out.println(str);
}
</pre>
<p><strong>Output:</strong></p>
<pre>
****** Selective Sort String Array *******
ab
aB
c
0
1Ad
2
a10
</pre>
<p>Happy sorting.. :)</p>
<div style="background-color: rgb(255, 241, 168); padding: 3px;" id="relatedpost"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2009/06/convert-arraylist-to-arrays-in-java.html" title="Convert ArrayList to Arrays in Java">Convert ArrayList to Arrays in Java</a></li><li><a href="http://viralpatel.net/blogs/2010/07/java-calculate-free-disk-space-java-apache-commons-io.html" title="Calculate Free Disk Space in Java using Apache Commons IO">Calculate Free Disk Space in Java using Apache Commons IO</a></li><li><a href="http://viralpatel.net/blogs/2009/07/static-import-java-example-tutorial.html" title="Static Import in Java: New way to Import things in Java!">Static Import in Java: New way to Import things in Java!</a></li><li><a href="http://viralpatel.net/blogs/2009/05/how-to-execute-command-prompt-command-view-output-java.html" title="How to execute a command prompt command &#038; view output in Java">How to execute a command prompt command &#038; view output in Java</a></li><li><a href="http://viralpatel.net/blogs/2009/05/inspect-your-code-in-eclipse-using-eclipse-scrapbook-feature.html" title="Inspect your code in Eclipse using Eclipse Scrapbook feature">Inspect your code in Eclipse using Eclipse Scrapbook feature</a></li><li><a href="http://viralpatel.net/blogs/2009/05/getting-jvm-heap-size-used-memory-total-memory-using-java-runtime.html" title="Getting JVM heap size, used memory, total memory using Java Runtime">Getting JVM heap size, used memory, total memory using Java Runtime</a></li><li><a href="http://viralpatel.net/blogs/2009/04/parsing-reading-xml-file-in-java-xml-reading-java-tutorial.html" title="Parsing / Reading XML file in Java.">Parsing / Reading XML file in Java.</a></li><li><a href="http://viralpatel.net/blogs/2009/01/how-to-take-screen-shots-in-java-taking-screenshots-java.html" title="How to take screen shots in Java">How to take screen shots in Java</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2010/07/java-tip-how-to-sort-array-in-java-java-util-arrays.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2010/07/java-tip-how-to-sort-array-in-java-java-util-arrays.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2010/07/java-tip-how-to-sort-array-in-java-java-util-arrays.html&amp;title=Java Tip: How to Sort Arrays in Java using java.util.Arrays class&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2010/07/java-tip-how-to-sort-array-in-java-java-util-arrays.html&amp;title=Java Tip: How to Sort Arrays in Java using java.util.Arrays class" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2010/07/java-tip-how-to-sort-array-in-java-java-util-arrays.html&amp;title=Java Tip: How to Sort Arrays in Java using java.util.Arrays class" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2010/07/java-tip-how-to-sort-array-in-java-java-util-arrays.html&amp;title=Java Tip: How to Sort Arrays in Java using java.util.Arrays class" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>
<p><a href="http://feedads.g.doubleclick.net/~a/qs4K8oSQVMHwyhgw8EKt8Y_xp5U/0/da"><img src="http://feedads.g.doubleclick.net/~a/qs4K8oSQVMHwyhgw8EKt8Y_xp5U/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/qs4K8oSQVMHwyhgw8EKt8Y_xp5U/1/da"><img src="http://feedads.g.doubleclick.net/~a/qs4K8oSQVMHwyhgw8EKt8Y_xp5U/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=42Nqe6fgT0U:hvlqBOI7YoM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=42Nqe6fgT0U:hvlqBOI7YoM:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=42Nqe6fgT0U:hvlqBOI7YoM:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=42Nqe6fgT0U:hvlqBOI7YoM:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=42Nqe6fgT0U:hvlqBOI7YoM:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=42Nqe6fgT0U:hvlqBOI7YoM:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=42Nqe6fgT0U:hvlqBOI7YoM:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=42Nqe6fgT0U:hvlqBOI7YoM:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=42Nqe6fgT0U:hvlqBOI7YoM:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2010/07/java-tip-how-to-sort-array-in-java-java-util-arrays.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://viralpatel.net/blogs/2010/07/java-tip-how-to-sort-array-in-java-java-util-arrays.html</feedburner:origLink></item>
		<item>
		<title>Spring 3 MVC: Tiles Plugin Tutorial with Example in Eclipse</title>
		<link>http://feedproxy.google.com/~r/viralpatelnet/~3/hEPVRI4Azck/spring-3-mvc-tiles-plugin-tutorial-example-eclipse.html</link>
		<comments>http://viralpatel.net/blogs/2010/07/spring-3-mvc-tiles-plugin-tutorial-example-eclipse.html#comments</comments>
		<pubDate>Thu, 08 Jul 2010 12:50:42 +0000</pubDate>
		<dc:creator>Viral Patel</dc:creator>
				<category><![CDATA[Spring]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[spring mvc]]></category>
		<category><![CDATA[spring-3-mvc-series]]></category>
		<category><![CDATA[tiles]]></category>
		<category><![CDATA[tiles-plugin]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=2081</guid>
		<description><![CDATA[Welcome to Part 4 for Spring 3.0 MVC Series. In previous article we saw how to create a form using Spring 3 MVC and display it in JSP. Also we learn about annotation @ModelAttribute. In this part we will discuss about Tiles Framework and its Integration with Spring 3.0 MVC. We will add Tiles support [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to Part 4 for <strong>Spring 3.0 MVC Series</strong>. In <a target="_blank" href="http://viralpatel.net/blogs/2010/07/spring-3-mvc-handling-forms.html">previous article</a> we saw how to create a form using Spring 3 MVC and display it in JSP. Also we learn about annotation <code>@ModelAttribute</code>.</p>
<p>In this part we will discuss about Tiles Framework and its Integration with Spring 3.0 MVC. We will add Tiles support to our HelloWorld Spring application that we created in previous parts. I strongly recommend you to go through previous articles and download the source code of our sample application.</p>
<style type="text/css">#spring { color:#222222; width: 98%; background-color: #EEFF99; padding:5px; -moz-border-radius: 10px; -webkit-border-radius: 10px; }#spring h3 { font-size: 18px; text-decoration:underline; }#spring ul { list-style:none; }#spring ul li { padding:3px; }</style><div id="spring"><h3>Spring 3.0 MVC Series</h3><ul>	<li><a href="http://viralpatel.net/blogs/2010/06/tutorial-spring-3-mvc-introduction-spring-mvc-framework.html">Part 1: Introduction to Spring 3.0 MVC framework</a></li>	<li><a href="http://viralpatel.net/blogs/2010/06/spring-3-mvc-create-hello-world-application-spring-3-mvc.html">Part 2: Create Hello World Application in Spring 3.0 MVC</a></li>	<li><a href="http://viralpatel.net/blogs/2010/07/spring-3-mvc-handling-forms.html">Part 3: Handling Forms in Spring 3.0 MVC</a></li>	<li><a href="http://viralpatel.net/blogs/2010/07/spring-3-mvc-tiles-plugin-tutorial-example-eclipse.html">Part 4: Spring 3 MVC Tiles Plugin Tutorial with Example in Eclipse</a></li>	<li><a href="http://viralpatel.net/blogs/2010/07/spring-3-mvc-internationalization-i18n-localization-tutorial-example.html">Part 5: Spring 3 MVC Internationalization & Localization Tutorial with Example in Eclipse</a></li></ul></div>
<h2>Introduction to Tiles 2</h2>
<p>Nowadays, website are generally divided into pieces of reusable template that are being rendered among different web pages. For example a site containing header, footer, menu etc. This items remains same through out the website and give it a common look and feel. It is very difficult to hard code this in each and every webpage and if later a change is needed than all the pages needs to be modified. Hence we use templatization mechanism. We create a common Header, Footer, Menu page and include this in each page.</p>
<p>Tiles Plugin allow both templating and componentization. In fact, both mechanisms are similar: you<br />
define parts of page (a &#8220;Tile&#8221;) that you assemble to build another part or a full page. A part can<br />
take parameters, allowing dynamic content, and can be seen as a method in JAVA language. Tiles is a templating system used to maintain a consistent look and feel across all the web pages of a web application. It increase the reusability of template and reduce code duplication.</p>
<p>A common layout of website is defined in a central configuration file and this layout can be extended across all the webpages of the web application.</p>
<h2>Our Application Layout</h2>
<p>Our goal is to add Header, Footer and Menu to our Spring 3 HelloWorld application. Following will be the layout of the same.</p>
<p><img alt="tiles-framework-layout" src="http://img.viralpatel.net/2009/12/struts2-tiles-layout.gif" title="tiles-framework-layout" class="aligncenter" width="359" height="321" /></p>
<h2>Required JAR files</h2>
<p>In order to add Tiles support to our Spring3 application, we will need few jar files. Following is the list of JARs in our example. Add these JARs in WEB-INF/lib folder.<br />
<img src="http://img.viralpatel.net/2010/07/spring-3-tiles-framework-jar2.png" alt="spring-3-tiles-framework-jar" title="spring-3-tiles-framework-jar" width="325" height="340" class="aligncenter size-full wp-image-2082" /><br />
The highlighted jar files in above list are the new jars to be added in project for Tiles integration.</p>
<h2>Configuring Tiles framework in Spring MVC</h2>
<p>To configure Tiles, an entry for bean <code>TilesConfigure</code> has to be made in spring-servlet.xml. Open the spring-servlet.xml from WEB-INF folder and add following code between <code>&lt;beans&gt; &lt;/beans&gt;</code> tag.</p>
<p><em>File: /WebContent/WEB-INF/spring-servlet.xml</em></p>
<pre class="brush: xml;">
	&lt;bean id=&quot;viewResolver&quot;
		class=&quot;org.springframework.web.servlet.view.UrlBasedViewResolver&quot;&gt;
		&lt;property name=&quot;viewClass&quot;&gt;
			&lt;value&gt;
				org.springframework.web.servlet.view.tiles2.TilesView
			&lt;/value&gt;
		&lt;/property&gt;
	&lt;/bean&gt;
	&lt;bean id=&quot;tilesConfigurer&quot;
		class=&quot;org.springframework.web.servlet.view.tiles2.TilesConfigurer&quot;&gt;
		&lt;property name=&quot;definitions&quot;&gt;
			&lt;list&gt;
				&lt;value&gt;/WEB-INF/tiles.xml&lt;/value&gt;
			&lt;/list&gt;
		&lt;/property&gt;
	&lt;/bean&gt;
</pre>
<p>An input configuration file /WEB-INF/tiles.xml is passed as argument in above bean definition. This file contains the Tiles definition for our web application.</p>
<p>Create a file tiles.xml in WEB-INF folder and copy following code into it.<br />
<img alt="tiles-xml-spring-mvc" src="http://img.viralpatel.net/2009/12/struts2-tiles-xml.png" title="tiles-xml-spring-mvc" class="aligncenter" width="129" height="104" /></p>
<p><em>File: WebContent/WEB-INF/tiles.xml</em></p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;
&lt;!DOCTYPE tiles-definitions PUBLIC
       &quot;-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN&quot;
       &quot;http://tiles.apache.org/dtds/tiles-config_2_0.dtd&quot;&gt;
&lt;tiles-definitions&gt;
	&lt;definition name=&quot;base.definition&quot;
		template=&quot;/WEB-INF/jsp/layout.jsp&quot;&gt;
		&lt;put-attribute name=&quot;title&quot; value=&quot;&quot; /&gt;
		&lt;put-attribute name=&quot;header&quot; value=&quot;/WEB-INF/jsp/header.jsp&quot; /&gt;
		&lt;put-attribute name=&quot;menu&quot; value=&quot;/WEB-INF/jsp/menu.jsp&quot; /&gt;
		&lt;put-attribute name=&quot;body&quot; value=&quot;&quot; /&gt;
		&lt;put-attribute name=&quot;footer&quot; value=&quot;/WEB-INF/jsp/footer.jsp&quot; /&gt;
	&lt;/definition&gt;

	&lt;definition name=&quot;contact&quot; extends=&quot;base.definition&quot;&gt;
		&lt;put-attribute name=&quot;title&quot; value=&quot;Contact Manager&quot; /&gt;
		&lt;put-attribute name=&quot;body&quot; value=&quot;/WEB-INF/jsp/contact.jsp&quot; /&gt;
	&lt;/definition&gt;

&lt;/tiles-definitions&gt;
</pre>
<p>Here in tiles.xml we have define a template base.definition. This layout contains attributes such as Header, Title, Body, Menu and Footer. The layout is then extended and new definitions for Contact page. We have override the default layout and changed the content for Body and Title. </p>
<h2>Creating View &#8211; The JSPs</h2>
<p><img src="http://img.viralpatel.net/2010/07/spring-tiles-jsp-files.png" alt="spring-tiles-jsp-files" title="spring-tiles-jsp-files" width="152" height="201" class="aligncenter size-full wp-image-2083" /></p>
<p>We will define the template for our webapplication in a JSP file called layout.jsp. This template will contain different segments of web page (Header, Footer, Menu etc). Create four new JSP files layout.jsp, header.jsp, menu.jsp and footer.jsp and copy following content in each of them.</p>
<p><em>File: WebContent/WEB-INF/jsp/layout.jsp</em></p>
<pre class="brush: xml;">
&lt;%@ taglib uri=&quot;http://tiles.apache.org/tags-tiles&quot; prefix=&quot;tiles&quot;%&gt;
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;
&quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;
&lt;title&gt;&lt;tiles:insertAttribute name=&quot;title&quot; ignore=&quot;true&quot; /&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;2&quot; cellspacing=&quot;2&quot; align=&quot;center&quot;&gt;
	&lt;tr&gt;
		&lt;td height=&quot;30&quot; colspan=&quot;2&quot;&gt;&lt;tiles:insertAttribute name=&quot;header&quot; /&gt;
		&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td height=&quot;250&quot;&gt;&lt;tiles:insertAttribute name=&quot;menu&quot; /&gt;&lt;/td&gt;
		&lt;td width=&quot;350&quot;&gt;&lt;tiles:insertAttribute name=&quot;body&quot; /&gt;&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td height=&quot;30&quot; colspan=&quot;2&quot;&gt;&lt;tiles:insertAttribute name=&quot;footer&quot; /&gt;
		&lt;/td&gt;
	&lt;/tr&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><em>File: WebContent/WEB-INF/jsp/header.jsp</em></p>
<pre class="brush: xml;">
&lt;h1&gt;Header&lt;/h1&gt;
</pre>
<p><em>File: WebContent/WEB-INF/jsp/menu.jsp</em></p>
<pre class="brush: xml;">
&lt;p&gt;Menu&lt;/p&gt;
</pre>
<p><em>File: WebContent/WEB-INF/jsp/footer.jsp</em></p>
<pre class="brush: xml;">
&lt;p&gt;Copyright &amp;copy; ViralPatel.net&lt;/p&gt;
</pre>
<h2>That’s All Folks</h2>
<p>Compile and Execute the application in Eclipse and see that the header, menu and footer are properly applied.<br />
<img src="http://img.viralpatel.net/2010/07/spring-tiles-demo-screen-contact-manager.png" alt="spring-tiles-demo-screen-contact-manager" title="spring-tiles-demo-screen-contact-manager" width="433" height="493" class="aligncenter size-full wp-image-2084" /></p>
<h2>Download Source Code</h2>
<p><a href="http://viralpatel.net/blogs/download/spring/spring-3-mvc-series/Spring3MVC-part3.zip">Click here to download Source Code (8.88kb).</a></p>
<h2>Moving On</h2>
<p>Today we saw how we can configure Tiles framework with Spring 3 MVC application. We used org.springframework.web.servlet.view.tiles2.TilesConfigurer class in bean definition to define the tiles configuration file. In <a href="http://viralpatel.net/blogs/2010/07/spring-3-mvc-internationalization-i18n-localization-tutorial-example.html">next part</a> we will discuss about Internationalization/Localization and adding its support in Spring 3 MVC. I hope you liked this article. Feel free to post your queries and comments in comment section.</p>
<div style="background-color: rgb(255, 241, 168); padding: 3px;" id="relatedpost"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2010/07/spring-3-mvc-internationalization-i18n-localization-tutorial-example.html" title="Spring 3 MVC: Internationalization &#038; Localization Tutorial with Example">Spring 3 MVC: Internationalization &#038; Localization Tutorial with Example</a></li><li><a href="http://viralpatel.net/blogs/2010/07/spring-3-mvc-handling-forms.html" title="Spring 3 MVC: Handling Forms in Spring 3.0 MVC">Spring 3 MVC: Handling Forms in Spring 3.0 MVC</a></li><li><a href="http://viralpatel.net/blogs/2010/06/spring-3-mvc-create-hello-world-application-spring-3-mvc.html" title="Spring 3 MVC: Create Hello World application in Spring 3.0 MVC">Spring 3 MVC: Create Hello World application in Spring 3.0 MVC</a></li><li><a href="http://viralpatel.net/blogs/2010/06/tutorial-spring-3-mvc-introduction-spring-mvc-framework.html" title="Spring 3 MVC – Introduction to Spring 3 MVC Framework">Spring 3 MVC – Introduction to Spring 3 MVC Framework</a></li><li><a href="http://viralpatel.net/blogs/2009/12/struts-2-tiles-plugin-tutorial-with-example-in-eclipse.html" title="Struts 2 Tiles Plugin Tutorial with Example in Eclipse">Struts 2 Tiles Plugin Tutorial with Example in Eclipse</a></li><li><a href="http://viralpatel.net/blogs/2008/12/tutorial-struts-tiles-plugin-example-in-eclipse.html" title="Tutorial: Struts Tiles plugin example in Eclipse">Tutorial: Struts Tiles plugin example in Eclipse</a></li><li><a href="http://viralpatel.net/blogs/2010/01/configuring-mdp-and-controlling-it-with-and-without-jmx.html" title="Configuring MDP and Controlling it With and Without JMX">Configuring MDP and Controlling it With and Without JMX</a></li><li><a href="http://viralpatel.net/blogs/2008/12/tutorial-struts-spring-framework-example-in-eclipse.html" title="Tutorial:Struts Spring framework example in Eclipse.">Tutorial:Struts Spring framework example in Eclipse.</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2010/07/spring-3-mvc-tiles-plugin-tutorial-example-eclipse.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2010/07/spring-3-mvc-tiles-plugin-tutorial-example-eclipse.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2010/07/spring-3-mvc-tiles-plugin-tutorial-example-eclipse.html&amp;title=Spring 3 MVC: Tiles Plugin Tutorial with Example in Eclipse&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2010/07/spring-3-mvc-tiles-plugin-tutorial-example-eclipse.html&amp;title=Spring 3 MVC: Tiles Plugin Tutorial with Example in Eclipse" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2010/07/spring-3-mvc-tiles-plugin-tutorial-example-eclipse.html&amp;title=Spring 3 MVC: Tiles Plugin Tutorial with Example in Eclipse" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2010/07/spring-3-mvc-tiles-plugin-tutorial-example-eclipse.html&amp;title=Spring 3 MVC: Tiles Plugin Tutorial with Example in Eclipse" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>
<p><a href="http://feedads.g.doubleclick.net/~a/e01ivCFm2AuL0RZuPdq46-EA15k/0/da"><img src="http://feedads.g.doubleclick.net/~a/e01ivCFm2AuL0RZuPdq46-EA15k/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/e01ivCFm2AuL0RZuPdq46-EA15k/1/da"><img src="http://feedads.g.doubleclick.net/~a/e01ivCFm2AuL0RZuPdq46-EA15k/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=hEPVRI4Azck:xshHTWqX0wA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=hEPVRI4Azck:xshHTWqX0wA:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=hEPVRI4Azck:xshHTWqX0wA:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=hEPVRI4Azck:xshHTWqX0wA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=hEPVRI4Azck:xshHTWqX0wA:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=hEPVRI4Azck:xshHTWqX0wA:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=hEPVRI4Azck:xshHTWqX0wA:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=hEPVRI4Azck:xshHTWqX0wA:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=hEPVRI4Azck:xshHTWqX0wA:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2010/07/spring-3-mvc-tiles-plugin-tutorial-example-eclipse.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://viralpatel.net/blogs/2010/07/spring-3-mvc-tiles-plugin-tutorial-example-eclipse.html</feedburner:origLink></item>
		<item>
		<title>Spring 3 MVC: Handling Forms in Spring 3.0 MVC</title>
		<link>http://feedproxy.google.com/~r/viralpatelnet/~3/An07Y2NluwA/spring-3-mvc-handling-forms.html</link>
		<comments>http://viralpatel.net/blogs/2010/07/spring-3-mvc-handling-forms.html#comments</comments>
		<pubDate>Mon, 05 Jul 2010 14:14:57 +0000</pubDate>
		<dc:creator>Viral Patel</dc:creator>
				<category><![CDATA[Spring]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[spring mvc]]></category>
		<category><![CDATA[spring-3-mvc-series]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=2074</guid>
		<description><![CDATA[Welcome to the Part 3 of Spring 3.0 MVC Series. In previous article we created a Hello World application in Spring MVC. We leaned how to configure Spring MVC in web.xml and how to use different annotations like @Controller, @RequestMapping etc. In this article let us see how to handle forms in Spring 3.0 MVC. [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to the Part 3 of <strong>Spring 3.0 MVC Series</strong>. In <a target="_new" rel="nofollow" href="http://viralpatel.net/blogs/2010/06/spring-3-mvc-create-hello-world-application-spring-3-mvc.html">previous article</a> we created a Hello World application in Spring MVC. We leaned how to configure Spring MVC in web.xml and how to use different annotations like @Controller, @RequestMapping etc. In this article let us see how to handle forms in Spring 3.0 MVC.</p>
<style type="text/css">#spring { color:#222222; width: 98%; background-color: #EEFF99; padding:5px; -moz-border-radius: 10px; -webkit-border-radius: 10px; }#spring h3 { font-size: 18px; text-decoration:underline; }#spring ul { list-style:none; }#spring ul li { padding:3px; }</style><div id="spring"><h3>Spring 3.0 MVC Series</h3><ul>	<li><a href="http://viralpatel.net/blogs/2010/06/tutorial-spring-3-mvc-introduction-spring-mvc-framework.html">Part 1: Introduction to Spring 3.0 MVC framework</a></li>	<li><a href="http://viralpatel.net/blogs/2010/06/spring-3-mvc-create-hello-world-application-spring-3-mvc.html">Part 2: Create Hello World Application in Spring 3.0 MVC</a></li>	<li><a href="http://viralpatel.net/blogs/2010/07/spring-3-mvc-handling-forms.html">Part 3: Handling Forms in Spring 3.0 MVC</a></li>	<li><a href="http://viralpatel.net/blogs/2010/07/spring-3-mvc-tiles-plugin-tutorial-example-eclipse.html">Part 4: Spring 3 MVC Tiles Plugin Tutorial with Example in Eclipse</a></li>	<li><a href="http://viralpatel.net/blogs/2010/07/spring-3-mvc-internationalization-i18n-localization-tutorial-example.html">Part 5: Spring 3 MVC Internationalization & Localization Tutorial with Example in Eclipse</a></li></ul></div>
<p>We will use the framework that we created in previous article as a base reference and add up the functionality of form in it. Also the application that we create will be a Contact Manager application.</p>
<h2>Our Goal</h2>
<p>Our goal is to create basic Contact Manager application. This app will have a form to take contact details from user. For now we will just print the details in logs. We will learn how to capture the form data in Spring 3 MVC.<br />
<img src="http://img.viralpatel.net/2010/07/spring-3-contact-manager-form.png" alt="spring-3-contact-manager-form" title="spring-3-contact-manager-form" width="348" height="297" class="aligncenter size-full wp-image-2078" /></p>
<h2>Getting Started</h2>
<p>Let us add the contact form to our Spring 3 MVC Hello World application. Open the index.jsp file and change it to following:</p>
<p><em>File: WebContent/index.jsp</em></p>
<pre class="brush: xml;">
&lt;jsp:forward page=&quot;contacts.html&quot;&gt;&lt;/jsp:forward&gt;
</pre>
<p>The above code will just redirect the user to contacts.html page.</p>
<h2>The View- contact.jsp</h2>
<p>Create a JSP file that will display Contact form to our users.<br />
<em>File: /WebContent/WEB-INF/jsp/contact.jsp</em></p>
<pre class="brush: xml;">
&lt;%@taglib uri=&quot;http://www.springframework.org/tags/form&quot; prefix=&quot;form&quot;%&gt;
&lt;html&gt;
&lt;head&gt;
	&lt;title&gt;Spring 3 MVC Series - Contact Manager&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h2&gt;Contact Manager&lt;/h2&gt;
&lt;form:form method=&quot;post&quot; action=&quot;addContact.html&quot;&gt;

	&lt;table&gt;
	&lt;tr&gt;
		&lt;td&gt;&lt;form:label path=&quot;firstname&quot;&gt;First Name&lt;/form:label&gt;&lt;/td&gt;
		&lt;td&gt;&lt;form:input path=&quot;firstname&quot; /&gt;&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td&gt;&lt;form:label path=&quot;lastname&quot;&gt;Last Name&lt;/form:label&gt;&lt;/td&gt;
		&lt;td&gt;&lt;form:input path=&quot;lastname&quot; /&gt;&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td&gt;&lt;form:label path=&quot;lastname&quot;&gt;Email&lt;/form:label&gt;&lt;/td&gt;
		&lt;td&gt;&lt;form:input path=&quot;email&quot; /&gt;&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td&gt;&lt;form:label path=&quot;lastname&quot;&gt;Telephone&lt;/form:label&gt;&lt;/td&gt;
		&lt;td&gt;&lt;form:input path=&quot;telephone&quot; /&gt;&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
		&lt;td colspan=&quot;2&quot;&gt;
			&lt;input type=&quot;submit&quot; value=&quot;Add Contact&quot;/&gt;
		&lt;/td&gt;
	&lt;/tr&gt;
&lt;/table&gt;	

&lt;/form:form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Here in above JSP, we have displayed a form. Note that the form is getting submitted to <strong>addContact.html</strong> page.</p>
<h2>Adding Form and Controller in Spring 3</h2>
<p>We will now add the logic in Spring 3 to display the form and fetch the values from it. For that we will create two java files. First the <code>Contact.java</code> which is nothing but the form to display/retrieve data from screen and second the <code>ContactController.java</code> which is the spring controller class.<br />
<img src="http://img.viralpatel.net/2010/07/contact-form-package-spring-mvc.png" alt="contact-form-package-spring-mvc" title="contact-form-package-spring-mvc" width="243" height="122" class="aligncenter size-full wp-image-2079" /></p>
<p><em>File: net.viralpatel.spring3.form.Contact</em></p>
<pre class="brush: java;">
package net.viralpatel.spring3.form;

public class Contact {
	private String firstname;
	private String lastname;
	private String email;
	private String telephone;

	//.. getter and setter for all above fields.

}
</pre>
<p>The above file is the contact form which holds the data from screen. Note that I haven&#8217;t showed the getter and setter methods. You can generate these methods by pressiong <strong>Alt + Shift + S, R</strong>.</p>
<p><em>File: net.viralpatel.spring3.controller.ContactController</em></p>
<pre class="brush: java;">
package net.viralpatel.spring3.controller;

import net.viralpatel.spring3.form.Contact;

import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

@Controller
@SessionAttributes
public class ContactController {

	@RequestMapping(value = &quot;/addContact&quot;, method = RequestMethod.POST)
	public String addContact(@ModelAttribute(&quot;contact&quot;)
							Contact contact, BindingResult result) {

		System.out.println(&quot;First Name:&quot; + contact.getFirstname() +
					&quot;Last Name:&quot; + contact.getLastname());

		return &quot;redirect:contacts.html&quot;;
	}

	@RequestMapping(&quot;/contacts&quot;)
	public ModelAndView showContacts() {

		return new ModelAndView(&quot;contact&quot;, &quot;command&quot;, new Contact());
	}
}
</pre>
<p>In above controller class, note that we have created two methods with Request Mapping <strong>/contacts</strong> and <strong>/addContact</strong>. The method <code>showContacts()</code> will be called when user request for a url contacts.html. This method will render a model with name &#8220;contact&#8221;. Note that in the <code>ModelAndView</code> object we have passed a blank Contact object with name &#8220;command&#8221;. The spring framework expects an object with name command if you are using<br />
<form:form> in your JSP file.</p>
<p>Also note that in method <code>addContact()</code> we have annotated this method with <code>RequestMapping</code> and passed an attribute method=&#8221;RequestMethod.POST&#8221;. Thus the method will be called only when user generates a POST method request to the url /addContact.html. We have annotated the argument Contact with annotation <code>@ModelAttribute</code>. This will binds the data from request to the object Contact. In this method we just have printed values of Firstname and Lastname and redirected the view to cotnacts.html.</p>
<h2>That&#8217;s all folks</h2>
<p>The form is completed now. Just run the application in eclipse by pression Alt + Shift + X, R. It will show the contact form. Just enter view values and press Add button. Once you press the button, it will print the firstname and lastname in sysout logs.<br />
<img src="http://img.viralpatel.net/2010/07/spring-3-contact-manager-form.png" alt="spring-3-contact-manager-form" title="spring-3-contact-manager-form" width="348" height="297" class="aligncenter size-full wp-image-2078" /></p>
<h2>Download Source Code</h2>
<p><a href="http://viralpatel.net/blogs/download/spring/spring-3-mvc-series/Spring3MVC-part2.zip">Click here to download source code (7.43kb)</a></p>
<h2>Moving on</h2>
<p>In this article we learn how to create a form using Spring 3 MVC and display it in JSP. Also we learn how to retrieve the form values using ModelAttribute annotation. In <a target="_blank" href="http://viralpatel.net/blogs/2010/07/spring-3-mvc-tiles-plugin-tutorial-example-eclipse.html">next section</a> we will go through form validations and different data conversion methods in Spring 3 MVC.</p>
<div style="background-color: rgb(255, 241, 168); padding: 3px;" id="relatedpost"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2010/06/tutorial-spring-3-mvc-introduction-spring-mvc-framework.html" title="Spring 3 MVC – Introduction to Spring 3 MVC Framework">Spring 3 MVC – Introduction to Spring 3 MVC Framework</a></li><li><a href="http://viralpatel.net/blogs/2010/07/spring-3-mvc-internationalization-i18n-localization-tutorial-example.html" title="Spring 3 MVC: Internationalization &#038; Localization Tutorial with Example">Spring 3 MVC: Internationalization &#038; Localization Tutorial with Example</a></li><li><a href="http://viralpatel.net/blogs/2010/07/spring-3-mvc-tiles-plugin-tutorial-example-eclipse.html" title="Spring 3 MVC: Tiles Plugin Tutorial with Example in Eclipse">Spring 3 MVC: Tiles Plugin Tutorial with Example in Eclipse</a></li><li><a href="http://viralpatel.net/blogs/2010/06/spring-3-mvc-create-hello-world-application-spring-3-mvc.html" title="Spring 3 MVC: Create Hello World application in Spring 3.0 MVC">Spring 3 MVC: Create Hello World application in Spring 3.0 MVC</a></li><li><a href="http://viralpatel.net/blogs/2010/01/configuring-mdp-and-controlling-it-with-and-without-jmx.html" title="Configuring MDP and Controlling it With and Without JMX">Configuring MDP and Controlling it With and Without JMX</a></li><li><a href="http://viralpatel.net/blogs/2009/02/tutorial-creating-javaserver-faces-jsf-application-in-eclipse-jsf-project-jsf-tutorial.html" title="Tutorial: Creating JavaServer Faces JSF application in Eclipse">Tutorial: Creating JavaServer Faces JSF application in Eclipse</a></li><li><a href="http://viralpatel.net/blogs/2008/12/tutorial-struts-spring-framework-example-in-eclipse.html" title="Tutorial:Struts Spring framework example in Eclipse.">Tutorial:Struts Spring framework example in Eclipse.</a></li><li><a href="http://viralpatel.net/blogs/2008/12/tutorial-creating-struts-application-in-eclipse.html" title="Tutorial: Creating Struts application in Eclipse">Tutorial: Creating Struts application in Eclipse</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2010/07/spring-3-mvc-handling-forms.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2010/07/spring-3-mvc-handling-forms.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2010/07/spring-3-mvc-handling-forms.html&amp;title=Spring 3 MVC: Handling Forms in Spring 3.0 MVC&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2010/07/spring-3-mvc-handling-forms.html&amp;title=Spring 3 MVC: Handling Forms in Spring 3.0 MVC" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2010/07/spring-3-mvc-handling-forms.html&amp;title=Spring 3 MVC: Handling Forms in Spring 3.0 MVC" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2010/07/spring-3-mvc-handling-forms.html&amp;title=Spring 3 MVC: Handling Forms in Spring 3.0 MVC" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>
<p><a href="http://feedads.g.doubleclick.net/~a/ZOYNXh57hGswJEaXnpLlWzhG0c8/0/da"><img src="http://feedads.g.doubleclick.net/~a/ZOYNXh57hGswJEaXnpLlWzhG0c8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/ZOYNXh57hGswJEaXnpLlWzhG0c8/1/da"><img src="http://feedads.g.doubleclick.net/~a/ZOYNXh57hGswJEaXnpLlWzhG0c8/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=An07Y2NluwA:L7mzjJbiA0o:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=An07Y2NluwA:L7mzjJbiA0o:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=An07Y2NluwA:L7mzjJbiA0o:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=An07Y2NluwA:L7mzjJbiA0o:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=An07Y2NluwA:L7mzjJbiA0o:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=An07Y2NluwA:L7mzjJbiA0o:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=An07Y2NluwA:L7mzjJbiA0o:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=An07Y2NluwA:L7mzjJbiA0o:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=An07Y2NluwA:L7mzjJbiA0o:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2010/07/spring-3-mvc-handling-forms.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://viralpatel.net/blogs/2010/07/spring-3-mvc-handling-forms.html</feedburner:origLink></item>
		<item>
		<title>Generating Random Data in Oracle</title>
		<link>http://feedproxy.google.com/~r/viralpatelnet/~3/MFUTcpyrCOw/generating-random-data-in-oracle.html</link>
		<comments>http://viralpatel.net/blogs/2010/07/generating-random-data-in-oracle.html#comments</comments>
		<pubDate>Thu, 01 Jul 2010 17:06:06 +0000</pubDate>
		<dc:creator>Anuj Parashar</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[database queries]]></category>
		<category><![CDATA[oracle]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=2076</guid>
		<description><![CDATA[Most of the times, production data is not available in development environments. Here, I would like to share a single sql command which can generate random data. But before that, let&#8217;s address another issue faced by a lot of new oracle users. We need to generate a sequence of numbers using a sql statement. This will [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" src="http://img.viralpatel.net/2009/08/random-number.jpg" alt="random-numbers-oracle" width="225" height="150" />Most of the times, production data is not available in development environments. Here, I would like to share a single sql command which can generate random data. But before that, let&#8217;s address another issue faced by a lot of new oracle users. We need to generate a sequence of numbers using a sql statement. This will generate a number sequence. Nothing fancy, simplest of sql known :) Here it is:</p>
<pre class="brush: sql;">
SELECT ROWNUM
FROM DUAL
CONNECT BY LEVEL &lt; 10000;
</pre>
<p>Now, to generate the random data, the oracle build in package &#8220;dbms_random&#8221; comes handy. I am referring to the version 10GR2, there might be additional features available on 11G . Other build in functions can also be used. Here is a sample sql:</p>
<pre class="brush: sql;">
SELECT     LEVEL                                                       empl_id,
           MOD (ROWNUM, 50000)                                         dept_id,
           TRUNC (DBMS_RANDOM.VALUE (1000, 500000), 2)                 salary,
           DECODE (ROUND (DBMS_RANDOM.VALUE (1, 2)), 1, 'M', 2, 'F')   gender,
           TO_DATE (   ROUND (DBMS_RANDOM.VALUE (1, 28))
                    || '-'
                    || ROUND (DBMS_RANDOM.VALUE (1, 12))
                    || '-'
                    || ROUND (DBMS_RANDOM.VALUE (1900, 2010)),
                    'DD-MM-YYYY'
                   )                                                   dob,
           DBMS_RANDOM.STRING ('x', DBMS_RANDOM.VALUE (20, 50))        address
      FROM DUAL
CONNECT BY LEVEL &lt; 10000;
</pre>
<p>You can create a table using this sql and that will give you some random test data to work on. The output looks something like:</p>
<pre style="width:100%;overflow:auto;padding:3px;">EMPL_ID | DEPT_ID | SALARY    | GENDER | DOB       | ADDRESS
1       | 1       | 385433.6  | M      | 2/25/1903 | VVGJOPVIHD8HZELHK1SXWQ1RTNK84NT6
2       | 2       | 363024.64 | F      | 5/24/2010 | E4IOCU42LM7K2SS36OI0STDOO7A2UZ50L2Q5R1SME07
3       | 3       | 320010.48 | M      | 9/26/2009 | 8XM6CG3CSR6UA26PXPUTLPLPQNSQ3OJG7P0CL4XVHBMCVT
4       | 4       | 64230.96  | F      | 6/26/1991 | GLKYLEWG4NS0G67W64LF1G5GJPON5L8K93F
5       | 5       | 414134.44 | M      | 10/26/1981| QWXIT92XPEYYZZ0A8MR050ER8UJ30NYUHDJAEJHF2M3
...
...</pre>
<p>There are numerous functions which can be used to generate randomized data in different ways. Best is to create a wrapper package which can generate number, string, date etc based on the parameter passed and then call that package. I will share it as soon as I am done writing it.</p>
<div style="background-color: rgb(255, 241, 168); padding: 3px;" id="relatedpost"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2010/06/deleting-duplicate-rows-in-oracle.html" title="Deleting Duplicate Rows in Oracle">Deleting Duplicate Rows in Oracle</a></li><li><a href="http://viralpatel.net/blogs/2009/05/fetch-random-rows-from-database-mysql-oracle-ms-sql-postgresql-example.html" title="Fetch Random rows from Database (MySQL, Oracle, MS SQL, PostgreSQL)">Fetch Random rows from Database (MySQL, Oracle, MS SQL, PostgreSQL)</a></li><li><a href="http://viralpatel.net/blogs/2010/06/invisible-indexes-in-oracle-11g.html" title="Invisible Indexes in Oracle 11g">Invisible Indexes in Oracle 11g</a></li><li><a href="http://viralpatel.net/blogs/2010/06/oracle-data-compression.html" title="Oracle Data Compression">Oracle Data Compression</a></li><li><a href="http://viralpatel.net/blogs/2010/02/understanding-primary-keypk-constraint-in-oracle.html" title="Understanding Primary Key(PK) Constraint in Oracle">Understanding Primary Key(PK) Constraint in Oracle</a></li><li><a href="http://viralpatel.net/blogs/2010/07/java-calculate-free-disk-space-java-apache-commons-io.html" title="Calculate Free Disk Space in Java using Apache Commons IO">Calculate Free Disk Space in Java using Apache Commons IO</a></li><li><a href="http://viralpatel.net/blogs/2010/07/java-tip-how-to-sort-array-in-java-java-util-arrays.html" title="Java Tip: How to Sort Arrays in Java using java.util.Arrays class">Java Tip: How to Sort Arrays in Java using java.util.Arrays class</a></li><li><a href="http://viralpatel.net/blogs/2010/01/javascript-array-remove-element-js-array-delete-element.html" title="JavaScript Array Remove an Element ">JavaScript Array Remove an Element </a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2010/07/generating-random-data-in-oracle.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2010/07/generating-random-data-in-oracle.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2010/07/generating-random-data-in-oracle.html&amp;title=Generating Random Data in Oracle&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2010/07/generating-random-data-in-oracle.html&amp;title=Generating Random Data in Oracle" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2010/07/generating-random-data-in-oracle.html&amp;title=Generating Random Data in Oracle" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2010/07/generating-random-data-in-oracle.html&amp;title=Generating Random Data in Oracle" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>
<p><a href="http://feedads.g.doubleclick.net/~a/Ux33xP7BL8koUaBI5KNRRfaxZ2Y/0/da"><img src="http://feedads.g.doubleclick.net/~a/Ux33xP7BL8koUaBI5KNRRfaxZ2Y/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Ux33xP7BL8koUaBI5KNRRfaxZ2Y/1/da"><img src="http://feedads.g.doubleclick.net/~a/Ux33xP7BL8koUaBI5KNRRfaxZ2Y/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=MFUTcpyrCOw:T-AMyTi6Pg0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=MFUTcpyrCOw:T-AMyTi6Pg0:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=MFUTcpyrCOw:T-AMyTi6Pg0:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=MFUTcpyrCOw:T-AMyTi6Pg0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=MFUTcpyrCOw:T-AMyTi6Pg0:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=MFUTcpyrCOw:T-AMyTi6Pg0:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=MFUTcpyrCOw:T-AMyTi6Pg0:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=MFUTcpyrCOw:T-AMyTi6Pg0:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=MFUTcpyrCOw:T-AMyTi6Pg0:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2010/07/generating-random-data-in-oracle.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://viralpatel.net/blogs/2010/07/generating-random-data-in-oracle.html</feedburner:origLink></item>
		<item>
		<title>Deleting Duplicate Rows in Oracle</title>
		<link>http://feedproxy.google.com/~r/viralpatelnet/~3/fTmzoeCEoHA/deleting-duplicate-rows-in-oracle.html</link>
		<comments>http://viralpatel.net/blogs/2010/06/deleting-duplicate-rows-in-oracle.html#comments</comments>
		<pubDate>Thu, 24 Jun 2010 09:21:46 +0000</pubDate>
		<dc:creator>Anuj Parashar</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[database queries]]></category>
		<category><![CDATA[oracle]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=2069</guid>
		<description><![CDATA[Deleting duplicate rows from tables is one of the common task oracle developers come across. The data might get duplicated because of missing primary/unique key on the table or batch file getting loaded multiple times. Here I have tried to summarize different ways of deleting this duplicated data. Please note that this is not an [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-2070" src="http://img.viralpatel.net/2010/06/oracle-logo.jpg" alt="" width="268" height="41" />Deleting duplicate rows from tables is one of the common task oracle developers come across. The data might get duplicated because of missing primary/unique key on the table or batch file getting loaded multiple times. Here I have tried to summarize different ways of deleting this duplicated data. Please note that this is not an extensive list of all available methods but the ones I was able to figure out. This should serve as a handy reference while at work.</p>
<pre class="brush: sql;">
CREATE TABLE tbl_test(
	 SER_NO NUMBER,
 	 FST_NM VARCHAR2(30),
 	 DEPTID	NUMBER,
 	 CMNT   VARCHAR2(30));

INSERT INTO tbl_test VALUES(1, 'aaaaa', 2004, 'xxx');
INSERT INTO tbl_test VALUES(2, 'bbbbb', 2005, 'yyy');
INSERT INTO tbl_test VALUES(1, 'aaaaa', 2004, 'xxx');
INSERT INTO tbl_test VALUES(1, 'aaaaa', 2004, 'xxx');
INSERT INTO tbl_test VALUES(3, 'ccccc', 2005, 'zzz');
INSERT INTO tbl_test VALUES(2, 'bbbbb', 2005, 'yyy');
</pre>
<p><strong>1.</strong> <strong>Using MIN(rowid) :</strong> The most common method of removing duplicate rows.</p>
<pre class="brush: sql;">
DELETE FROM tbl_test
      WHERE ROWID NOT IN (SELECT   MIN (ROWID)
                              FROM tbl_test
                          GROUP BY ser_no, fst_nm, deptid, cmnt);
</pre>
<p><strong>Comment:</strong> This will take hours &amp; hours if the table is large (records in million).</p>
<p><strong>2.</strong> <strong>Using MIN(rowid) &amp; Join:</strong> More or less the same as first one</p>
<pre class="brush: sql;">
DELETE FROM tbl_test t
      WHERE t.ROWID NOT IN (SELECT MIN (b.ROWID)
                              FROM tbl_test b
                             WHERE b.ser_no = t.ser_no
                               AND b.fst_nm = t.fst_nm
                               AND b.deptid = t.deptid
                               AND b.cmnt   = t.cmnt);
</pre>
<p><strong>3. Using Subquery: </strong>This is an interesting one</p>
<pre class="brush: sql;">
DELETE FROM tbl_test
      WHERE ser_no IN (SELECT ser_no FROM tbl_test GROUP BY ser_no, fst_nm, deptid, cmnt HAVING COUNT (*) &gt; 1)
        AND fst_nm IN (SELECT fst_nm FROM tbl_test GROUP BY ser_no, fst_nm, deptid, cmnt HAVING COUNT (*) &gt; 1)
        AND deptid IN (SELECT deptid FROM tbl_test GROUP BY ser_no, fst_nm, deptid, cmnt HAVING COUNT (*) &gt; 1)
        AND cmnt   IN (SELECT cmnt   FROM tbl_test GROUP BY ser_no, fst_nm, deptid, cmnt HAVING COUNT (*) &gt; 1)
        AND ROWID NOT IN (SELECT   MIN (ROWID)
                              FROM tbl_test
                          GROUP BY ser_no, fst_nm, deptid, cmnt
                            HAVING COUNT (*) &gt; 1)
</pre>
<p><strong>Comment:</strong> A complicated way of performing the same task. Not efficient.</p>
<p><strong>4. Using Nested Subqueries:<br />
</strong></p>
<pre class="brush: sql;">
DELETE FROM tbl_test a
      WHERE (a.ser_no, a.fst_nm, a.deptid, a.cmnt) IN (SELECT b.ser_no, b.fst_nm, b.deptid, b.cmnt
                                                     FROM tbl_test b
                                                    WHERE a.ser_no = b.ser_no
                                                      AND a.fst_nm = b.fst_nm
                                                      AND a.deptid = b.deptid
                                                      AND a.cmnt   = b.cmnt
                                                      AND a.ROWID  &gt; b.ROWID);
</pre>
<p><strong>Comment:</strong> Will work but for large tables, this is not efficient.</p>
<p><strong>5. Using Analytic Fucntions:</strong></p>
<pre class="brush: sql;">
DELETE FROM tbl_test
      WHERE ROWID IN (
               SELECT rid
                 FROM (SELECT ROWID rid,
                              ROW_NUMBER () OVER (PARTITION BY ser_no, fst_nm, deptid, cmnt ORDER BY ROWID) rn
                         FROM tbl_test)
                WHERE rn &lt;&gt; 1);
</pre>
<p><strong>Comments:</strong> This is by far one of the best solutions if the table is really really large. Using the invaluable power of Analytics.</p>
<p><strong>6. CREATE-DROP-RENAME:</strong>  This one is a more appropriate solution in terms of resource usage in the sense that if we have a really large table, then with delete option we are generating a huge amount of UNDO information.(if we want to rollback for any reason). Even worst, the rollback segment may not be large enough to hold your UNDO information and give error. CTAS comes handy in this case.<br />
Step 1.</p>
<pre class="brush: sql;">
CREATE  TABLE tbl_test1 NOLOGGING
   AS
   SELECT tbl_test .*
     FROM tbl_test tbl_test
    WHERE ROWID IN (SELECT rid
                      FROM (SELECT ROWID rid, ROW_NUMBER() OVER (PARTITION BY ser_no, fst_nm, deptid, cmnt ORDER BY ROWID) rn
                              FROM tbl_test)
                     WHERE rn&lt;&gt;1);
</pre>
<p>Step 2.</p>
<pre class="brush: sql;">
DROP TABLE tbl_test; --drop the original table with lots of duplicate
</pre>
<p>Step 3.</p>
<pre class="brush: sql;">
RENAME tbl_test1 TO tbl_test; -- your original table without duplicates.
</pre>
<p>In case you have some other method of deleting duplicate data, please share it.</p>
<div style="background-color: rgb(255, 241, 168); padding: 3px;" id="relatedpost"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2010/07/generating-random-data-in-oracle.html" title="Generating Random Data in Oracle">Generating Random Data in Oracle</a></li><li><a href="http://viralpatel.net/blogs/2009/05/fetch-random-rows-from-database-mysql-oracle-ms-sql-postgresql-example.html" title="Fetch Random rows from Database (MySQL, Oracle, MS SQL, PostgreSQL)">Fetch Random rows from Database (MySQL, Oracle, MS SQL, PostgreSQL)</a></li><li><a href="http://viralpatel.net/blogs/2010/06/invisible-indexes-in-oracle-11g.html" title="Invisible Indexes in Oracle 11g">Invisible Indexes in Oracle 11g</a></li><li><a href="http://viralpatel.net/blogs/2010/06/oracle-data-compression.html" title="Oracle Data Compression">Oracle Data Compression</a></li><li><a href="http://viralpatel.net/blogs/2010/02/understanding-primary-keypk-constraint-in-oracle.html" title="Understanding Primary Key(PK) Constraint in Oracle">Understanding Primary Key(PK) Constraint in Oracle</a></li><li><a href="http://viralpatel.net/blogs/2010/07/java-calculate-free-disk-space-java-apache-commons-io.html" title="Calculate Free Disk Space in Java using Apache Commons IO">Calculate Free Disk Space in Java using Apache Commons IO</a></li><li><a href="http://viralpatel.net/blogs/2010/07/java-tip-how-to-sort-array-in-java-java-util-arrays.html" title="Java Tip: How to Sort Arrays in Java using java.util.Arrays class">Java Tip: How to Sort Arrays in Java using java.util.Arrays class</a></li><li><a href="http://viralpatel.net/blogs/2010/01/javascript-array-remove-element-js-array-delete-element.html" title="JavaScript Array Remove an Element ">JavaScript Array Remove an Element </a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2010/06/deleting-duplicate-rows-in-oracle.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2010/06/deleting-duplicate-rows-in-oracle.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2010/06/deleting-duplicate-rows-in-oracle.html&amp;title=Deleting Duplicate Rows in Oracle&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2010/06/deleting-duplicate-rows-in-oracle.html&amp;title=Deleting Duplicate Rows in Oracle" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2010/06/deleting-duplicate-rows-in-oracle.html&amp;title=Deleting Duplicate Rows in Oracle" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2010/06/deleting-duplicate-rows-in-oracle.html&amp;title=Deleting Duplicate Rows in Oracle" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>
<p><a href="http://feedads.g.doubleclick.net/~a/IvYevN361XHVo0HoNeYCOt7nI3A/0/da"><img src="http://feedads.g.doubleclick.net/~a/IvYevN361XHVo0HoNeYCOt7nI3A/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/IvYevN361XHVo0HoNeYCOt7nI3A/1/da"><img src="http://feedads.g.doubleclick.net/~a/IvYevN361XHVo0HoNeYCOt7nI3A/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=fTmzoeCEoHA:kBT_en6fM-s:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=fTmzoeCEoHA:kBT_en6fM-s:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=fTmzoeCEoHA:kBT_en6fM-s:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=fTmzoeCEoHA:kBT_en6fM-s:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=fTmzoeCEoHA:kBT_en6fM-s:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=fTmzoeCEoHA:kBT_en6fM-s:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=fTmzoeCEoHA:kBT_en6fM-s:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=fTmzoeCEoHA:kBT_en6fM-s:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=fTmzoeCEoHA:kBT_en6fM-s:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2010/06/deleting-duplicate-rows-in-oracle.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://viralpatel.net/blogs/2010/06/deleting-duplicate-rows-in-oracle.html</feedburner:origLink></item>
		<item>
		<title>Facebook: Facts you probably didnt know</title>
		<link>http://feedproxy.google.com/~r/viralpatelnet/~3/Ow1t4W3rsSU/facebook-facts-you-didnt-know.html</link>
		<comments>http://viralpatel.net/blogs/2010/06/facebook-facts-you-didnt-know.html#comments</comments>
		<pubDate>Thu, 24 Jun 2010 07:41:09 +0000</pubDate>
		<dc:creator>Sneha</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[facebook]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=2072</guid>
		<description><![CDATA[Have you ever wondered how Facebook has grown rapidly in these recent years! Here is a wonderful info about Facebook. Image courtesy: onlineschools.org See also:oEmbed: An Open Format Every Developer Should Know About Gartner&#8217;s Hype Cycle Special Report for 2009What if the Facebook is a Country?Pillows for you: Try these Social Media PillowPre-crime &#038; Minority [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever wondered how Facebook has grown rapidly in these recent years! Here is a wonderful info about Facebook.<br />
<img src="http://img.viralpatel.net/2010/06/everything-about-facebook..jpg" alt="everything-about-facebook" title="everything-about-facebook" width="640" height="3200" class="aligncenter size-full wp-image-2073" /><br />
Image courtesy: <a rel="nofollow" target="_new" href="http://onlineschools.org">onlineschools.org</a></p>
<div style="background-color: rgb(255, 241, 168); padding: 3px;" id="relatedpost"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2010/01/oembed-open-format-web-developers.html" title="oEmbed: An Open Format Every Developer Should Know About">oEmbed: An Open Format Every Developer Should Know About</a></li><li><a href="http://viralpatel.net/blogs/2009/09/gartners-hype-cycle-special-report-2009.html" title=" Gartner&#8217;s Hype Cycle Special Report for 2009"> Gartner&#8217;s Hype Cycle Special Report for 2009</a></li><li><a href="http://viralpatel.net/blogs/2009/08/what-if-facebook-is-country.html" title="What if the Facebook is a Country?">What if the Facebook is a Country?</a></li><li><a href="http://viralpatel.net/blogs/2009/08/pillows-try-social-media-pillow.html" title="Pillows for you: Try these Social Media Pillow">Pillows for you: Try these Social Media Pillow</a></li><li><a href="http://viralpatel.net/blogs/2009/07/precrime-minority-report-real-facebook-england.html" title="Pre-crime &#038; Minority Report turns real through Facebook in England">Pre-crime &#038; Minority Report turns real through Facebook in England</a></li><li><a href="http://viralpatel.net/blogs/2009/06/facebook-vanity-urls-landrush-starts-june-13-midnight.html" title="Facebook Vanity URLs Landrush to starts on June 13 Midnight">Facebook Vanity URLs Landrush to starts on June 13 Midnight</a></li><li><a href="http://viralpatel.net/blogs/2009/05/gravatar-manage-your-user-avatars-for-free.html" title="Gravatar: Manage your user avatars for free">Gravatar: Manage your user avatars for free</a></li><li><a href="http://viralpatel.net/blogs/2009/05/web-30-is-around-the-corner.html" title="Web 3.0 is around the corner !">Web 3.0 is around the corner !</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2010/06/facebook-facts-you-didnt-know.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2010/06/facebook-facts-you-didnt-know.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2010/06/facebook-facts-you-didnt-know.html&amp;title=Facebook: Facts you probably didnt know&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2010/06/facebook-facts-you-didnt-know.html&amp;title=Facebook: Facts you probably didnt know" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2010/06/facebook-facts-you-didnt-know.html&amp;title=Facebook: Facts you probably didnt know" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2010/06/facebook-facts-you-didnt-know.html&amp;title=Facebook: Facts you probably didnt know" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>
<p><a href="http://feedads.g.doubleclick.net/~a/-ueoKaYGU8dR9mTfdNuEv7eF540/0/da"><img src="http://feedads.g.doubleclick.net/~a/-ueoKaYGU8dR9mTfdNuEv7eF540/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/-ueoKaYGU8dR9mTfdNuEv7eF540/1/da"><img src="http://feedads.g.doubleclick.net/~a/-ueoKaYGU8dR9mTfdNuEv7eF540/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=Ow1t4W3rsSU:s5Yi3IfrlY0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=Ow1t4W3rsSU:s5Yi3IfrlY0:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=Ow1t4W3rsSU:s5Yi3IfrlY0:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=Ow1t4W3rsSU:s5Yi3IfrlY0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=Ow1t4W3rsSU:s5Yi3IfrlY0:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=Ow1t4W3rsSU:s5Yi3IfrlY0:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=Ow1t4W3rsSU:s5Yi3IfrlY0:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=Ow1t4W3rsSU:s5Yi3IfrlY0:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=Ow1t4W3rsSU:s5Yi3IfrlY0:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2010/06/facebook-facts-you-didnt-know.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://viralpatel.net/blogs/2010/06/facebook-facts-you-didnt-know.html</feedburner:origLink></item>
		<item>
		<title>Spring 3 MVC: Create Hello World application in Spring 3.0 MVC</title>
		<link>http://feedproxy.google.com/~r/viralpatelnet/~3/Y_Kq28a6wec/spring-3-mvc-create-hello-world-application-spring-3-mvc.html</link>
		<comments>http://viralpatel.net/blogs/2010/06/spring-3-mvc-create-hello-world-application-spring-3-mvc.html#comments</comments>
		<pubDate>Tue, 22 Jun 2010 07:46:21 +0000</pubDate>
		<dc:creator>Viral Patel</dc:creator>
				<category><![CDATA[Spring]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[spring mvc]]></category>
		<category><![CDATA[spring-3-mvc-series]]></category>

		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=2063</guid>
		<description><![CDATA[Welcome to the Part 2 of Spring 3.0 MVC Series. In previous article we went through the Introduction of Spring MVC 3.0 framework, its request processing lifecycle and architecture diagram. In this article, let us create a simple Hello World application in Spring MVC 3.0. For creating the hello world demo application, we will use [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to the Part 2 of <strong>Spring 3.0 MVC Series</strong>. In <a target="_new" href="http://viralpatel.net/blogs/2010/06/tutorial-spring-3-mvc-introduction-spring-mvc-framework.html">previous article</a> we went through the Introduction of Spring MVC 3.0 framework, its request processing lifecycle and architecture diagram. In this article, let us create a simple Hello World application in Spring MVC 3.0.<br />
<style type="text/css">#spring { color:#222222; width: 98%; background-color: #EEFF99; padding:5px; -moz-border-radius: 10px; -webkit-border-radius: 10px; }#spring h3 { font-size: 18px; text-decoration:underline; }#spring ul { list-style:none; }#spring ul li { padding:3px; }</style><div id="spring"><h3>Spring 3.0 MVC Series</h3><ul>	<li><a href="http://viralpatel.net/blogs/2010/06/tutorial-spring-3-mvc-introduction-spring-mvc-framework.html">Part 1: Introduction to Spring 3.0 MVC framework</a></li>	<li><a href="http://viralpatel.net/blogs/2010/06/spring-3-mvc-create-hello-world-application-spring-3-mvc.html">Part 2: Create Hello World Application in Spring 3.0 MVC</a></li>	<li><a href="http://viralpatel.net/blogs/2010/07/spring-3-mvc-handling-forms.html">Part 3: Handling Forms in Spring 3.0 MVC</a></li>	<li><a href="http://viralpatel.net/blogs/2010/07/spring-3-mvc-tiles-plugin-tutorial-example-eclipse.html">Part 4: Spring 3 MVC Tiles Plugin Tutorial with Example in Eclipse</a></li>	<li><a href="http://viralpatel.net/blogs/2010/07/spring-3-mvc-internationalization-i18n-localization-tutorial-example.html">Part 5: Spring 3 MVC Internationalization & Localization Tutorial with Example in Eclipse</a></li></ul></div><br />
For creating the hello world demo application, we will use Eclipse IDE.</p>
<h2>Things We Need</h2>
<p>Before we starts with our first Hello World Struts 2 Example, we will need few tools.</p>
<ol>
<li>JDK 1.5 above (<a rel="nofollow" href="http://java.sun.com/javase/downloads/index.jsp" target="_new">download</a>)</li>
<li>Tomcat 5.x above or any other container (Glassfish, JBoss, Websphere, Weblogic etc) (<a rel="nofollow" href="http://tomcat.apache.org/download-55.cgi" target="_new">download</a>)</li>
<li>Eclipse 3.2.x above (<a rel="nofollow" href="http://www.eclipse.org/downloads/" target="_new">download</a>)</li>
<li>Spring 3.0 MVC JAR files:(<a rel="nofollow" href="http://s3.amazonaws.com/dist.springframework.org/release/SPR/spring-framework-3.0.1.RELEASE-A.zip">download</a>). Following are the list of JAR files required for this application.
<ul>
<li>commons-logging-1.0.4.jar</li>
<li>jstl-1.2.jar</li>
<li>org.springframework.asm-3.0.1.RELEASE-A.jar</li>
<li>org.springframework.beans-3.0.1.RELEASE-A.jar</li>
<li>org.springframework.context-3.0.1.RELEASE-A.jar</li>
<li>org.springframework.core-3.0.1.RELEASE-A.jar</li>
<li>org.springframework.expression-3.0.1.RELEASE-A.jar</li>
<li>org.springframework.web.servlet-3.0.1.RELEASE-A.jar</li>
<li>org.springframework.web-3.0.1.RELEASE-A.jar</li>
</ul>
</li>
</ol>
<p>Note that depending on the current version of Spring MVC, the version number of above jar files may change.</p>
<h2>Our Goal</h2>
<p>Our goal is to create a basic Spring MVC application using latest 3.0 version. There will be an index page which will display a link &#8220;Say Hello&#8221; to user. On clicking this link, user will be redirected to another page <strong>hello</strong> which will display a message &#8220;Hello World, Spring 3.0!&#8221;.<br />
<img src="http://img.viralpatel.net/2010/06/spring-mvc-hello-world-screen.png" alt="spring-mvc-hello-world-screen" title="spring-mvc-hello-world-screen" width="429" height="322" class="aligncenter size-full wp-image-2064" /></p>
<h2>Getting Started</h2>
<p>Let us start with our first Spring 3.0 MVC based application.<br />
Open Eclipse and goto File -> New -> Project and select <strong>Dynamic Web Project</strong> in the New Project wizard screen.<br />
<img class="aligncenter size-full wp-image-294" title="eclipse-new-project-struts-example" src="http://img.viralpatel.net/2008/12/eclipse-new-project-struts-example.png" alt="Dynamic Web Project in Eclipse" width="369" height="365" /></p>
<p>After selecting Dynamic Web Project, press <strong>Next</strong>.</p>
<p><img src="http://img.viralpatel.net/2010/06/eclipse-dynamic-web-project.png" alt="eclipse-dynamic-web-project" title="eclipse-dynamic-web-project" width="373" height="458" class="aligncenter size-full wp-image-2065" /></p>
<p>Write the name of the project. For example Spring3MVC. Once this is done, select the target runtime environment (e.g. Apache Tomcat v6.0). This is to run the project inside Eclipse environment. After this press Finish.</p>
<p>Once the project is created, you can see its structure in Project Explorer.<br />
<img src="http://img.viralpatel.net/2010/06/spring-mvc-3-eclipse-project.png" alt="spring-mvc-3-eclipse-project" title="spring-mvc-3-eclipse-project" width="502" height="484" class="aligncenter size-full wp-image-2066" /><br />
Now copy all the required JAR files in <strong>WebContent &gt; WEB-INF &gt; lib</strong> folder. Create this folder if it does not exists.<br />
<img src="http://img.viralpatel.net/2010/06/spring-3-mvc-jar-files.png" alt="spring-3-mvc-jar-files" title="spring-3-mvc-jar-files" width="361" height="221" class="aligncenter size-full wp-image-2067" /></p>
<h2>The Spring Controller Class</h2>
<p>We will need a spring mvc controller class that will process the request and display a &#8220;Hello World&#8221; message. For this we will create a package <code>net.viralpatel.spring3.controller</code> in the source folder. This package will contain the Controller file.<br />
<img src="http://img.viralpatel.net/2010/06/spring-3-package.png" alt="spring-3-package" title="spring-3-package" width="236" height="54" class="aligncenter size-full wp-image-2068" /></p>
<p>Create a class called <strong>HelloWorldController</strong> in net.viralpatel.spring3.controller package and copy following content into it.</p>
<p><em>File: net.viralpatel.spring3.controller.HelloWorldController</em></p>
<pre class="brush: java;">
package net.viralpatel.spring3.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class HelloWorldController {

	@RequestMapping(&quot;/hello&quot;)
	public ModelAndView helloWorld() {

		String message = &quot;Hello World, Spring 3.0!&quot;;
		return new ModelAndView(&quot;hello&quot;, &quot;message&quot;, message);
	}
}
</pre>
<p>Note that we have annotated the HelloWorldController class with <code>@Controller</code> and <code>@RequestMapping("/hello")</code> on line 7 and 10.  When Spring scans our package, it will recognize this bean as being a Controller bean for processing requests.  The <code>@RequestMapping</code> annotation tells Spring that this Controller should process all requests beginning with /hello in the URL path.  That includes <code>/hello/*</code> and <code>/hello.html</code>.</p>
<p>The hello() method returns <code>ModelAndView</code> object. The ModelAndView object tries to resolve to a view named &#8220;hello&#8221; and the data model is being passed back to the browser so we can access the data within the JSP. The logical view name will resolve to <code>"/WEB-INF/jsp/hello.jsp"</code>. We will discuss this shortly how the logical name &#8220;hello&#8221; which is return in ModelAndView object is mapped to path /WEB-INF/jsp/hello.jsp.</p>
<p>The ModelAndView object also contains a message with key &#8220;message&#8221; and value &#8220;Hello World, Spring 3.0!&#8221;. This is the data that we are passing to our view. Normally this will be a value object in form of java bean that will contain the data to be displayed on our view. Here we are simply passing a string.</p>
<h2>The View: Create JSP</h2>
<p>To display the hello world message we will create a JSP. Note that this JSP is created in folder /WEB-INF/jsp. Create <code>hello.jsp</code> under WEB-INF/jsp directory and copy following content into it.</p>
<p><em>File: WEB-INF/jsp/hello.jsp</em></p>
<pre class="brush: xml;">
&lt;html&gt;
&lt;head&gt;
	&lt;title&gt;Spring 3.0 MVC Series: Hello World - ViralPatel.net&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
	${message}
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>The above JSP simply display a message using expression <code>${message}</code>. Note that the name &#8220;message&#8221; is the one which we have set in <code>ModelAndView</code> object with the message string.</p>
<p>Also we will need an index.jsp file which will be the entry point of our application. Create a file index.jsp under WebContent folder in your project and copy following content into it.</p>
<p>File: WebContent/index.jsp</p>
<pre class="brush: xml;">
&lt;html&gt;
&lt;head&gt;
	&lt;title&gt;Spring 3.0 MVC Series: Index - ViralPatel.net&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;a href=&quot;hello.html&quot;&gt;Say Hello&lt;/a&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<h2>Mapping Spring MVC in WEB.xml</h2>
<p>As discussed in the previous article (Introduction to Spring 3.0 MVC), the entry point of Spring MVC application will be the Servlet define in deployment descriptor (web.xml). Hence we will define an entry of <code>org.springframework.web.servlet.DispatcherServlet</code> class in web.xml.<br />
Open web.xml file which is under WEB-INF folder and copy paste following code.</p>
<p><em>File: WEB-INF/web.xml</em></p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;web-app xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot;
	xmlns:web=&quot;http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot;
	xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot;
	id=&quot;WebApp_ID&quot; version=&quot;2.5&quot;&gt;
	&lt;display-name&gt;Spring3MVC&lt;/display-name&gt;
	&lt;welcome-file-list&gt;
		&lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
	&lt;/welcome-file-list&gt;

	&lt;servlet&gt;
		&lt;servlet-name&gt;spring&lt;/servlet-name&gt;
		&lt;servlet-class&gt;
			org.springframework.web.servlet.DispatcherServlet
		&lt;/servlet-class&gt;
		&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
	&lt;/servlet&gt;
	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;spring&lt;/servlet-name&gt;
		&lt;url-pattern&gt;*.html&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;
&lt;/web-app&gt;
</pre>
<p>The above code in web.xml will map DispatcherServlet with url pattern *.html. Also note that we have define index.jsp as welcome file.</p>
<p>One thing to note here is the name of servlet in &lt;servlet-name&gt; tag in web.xml. Once the DispatcherServlet is initialized, it will looks for a file name <code>[servlet-name]-servlet.xml</code> in WEB-INF folder of web application. In this example, the framework will look for file called <code>spring-servlet.xml</code>.</p>
<h2>Spring configuration file</h2>
<p>Create a file spring-servlet.xml in WEB-INF folder and copy following content into it.</p>
<p><em>File: WEB-INF/spring-servlet.xml</em></p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xmlns:p=&quot;http://www.springframework.org/schema/p&quot;
	xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
	xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans
		http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		http://www.springframework.org/schema/context
		http://www.springframework.org/schema/context/spring-context-3.0.xsd&quot;&gt;

	&lt;context:component-scan
		base-package=&quot;net.viralpatel.spring3.controller&quot; /&gt;

	&lt;bean id=&quot;viewResolver&quot;
		class=&quot;org.springframework.web.servlet.view.UrlBasedViewResolver&quot;&gt;
		&lt;property name=&quot;viewClass&quot;
			value=&quot;org.springframework.web.servlet.view.JstlView&quot; /&gt;
		&lt;property name=&quot;prefix&quot; value=&quot;/WEB-INF/jsp/&quot; /&gt;
		&lt;property name=&quot;suffix&quot; value=&quot;.jsp&quot; /&gt;
	&lt;/bean&gt;
&lt;/beans&gt;
</pre>
<p>In the above xml configuration file, we have defined a tag &lt;context:component-scan&gt;. This will allow Spring to load all the components from package <code>net.viralpatel.spring3.controller</code> and all its child packages. This will load our <code>HelloWorldController</code> class. Also we have defined a bean <code>viewResolver</code>. This bean will resolve the view and add prefix string <strong>/WEB-INF/jsp/</strong> and suffix <strong>.jsp</strong> to the view in ModelAndView. Note that in our HelloWorldController class, we have return a ModelAndView object with view name &#8220;hello&#8221;. This will be resolved to path /WEB-INF/jsp/hello.jsp.</p>
<h2>That&#8217;s All Folks</h2>
<p>You may want to run the application now and see the result. I assume you have already configured Tomcat in eclipse. All you need to do:<br />
Open Server view from <strong>Windows > Show View > Server</strong>. Right click in this view and select New > Server and add your server details.<br />
To run the project, right click on Project name from Project Explorer and select <strong>Run as > Run on Server (Shortcut: Alt+Shift+X, R)</strong><br />
<img src="http://img.viralpatel.net/2010/06/spring-mvc-hello-world-screen.png" alt="spring-mvc-hello-world-screen" title="spring-mvc-hello-world-screen" width="429" height="322" class="aligncenter size-full wp-image-2064" /></p>
<h2>Download Source Code</h2>
<p><a href="http://viralpatel.net/blogs/download/spring/spring-3-mvc-series/Spring3MVC-part1.zip">Click here to download source code (9.05kb)</a></p>
<h2>Moving On</h2>
<p>In this tutorial we created a small Hello World application using Spring 3.0 MVC framework. Also we learned about the spring configuration and different annotations like <code>@Controller</code> and <code>@RequestMapping</code>. In next article we will see how easy it is to handle form data using Spring 3.0 MVC.</p>
<div style="background-color: rgb(255, 241, 168); padding: 3px;" id="relatedpost"><h2  class="related_post_title">See also:</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2010/07/spring-3-mvc-internationalization-i18n-localization-tutorial-example.html" title="Spring 3 MVC: Internationalization &#038; Localization Tutorial with Example">Spring 3 MVC: Internationalization &#038; Localization Tutorial with Example</a></li><li><a href="http://viralpatel.net/blogs/2010/07/spring-3-mvc-tiles-plugin-tutorial-example-eclipse.html" title="Spring 3 MVC: Tiles Plugin Tutorial with Example in Eclipse">Spring 3 MVC: Tiles Plugin Tutorial with Example in Eclipse</a></li><li><a href="http://viralpatel.net/blogs/2010/07/spring-3-mvc-handling-forms.html" title="Spring 3 MVC: Handling Forms in Spring 3.0 MVC">Spring 3 MVC: Handling Forms in Spring 3.0 MVC</a></li><li><a href="http://viralpatel.net/blogs/2010/06/tutorial-spring-3-mvc-introduction-spring-mvc-framework.html" title="Spring 3 MVC – Introduction to Spring 3 MVC Framework">Spring 3 MVC – Introduction to Spring 3 MVC Framework</a></li><li><a href="http://viralpatel.net/blogs/2010/01/configuring-mdp-and-controlling-it-with-and-without-jmx.html" title="Configuring MDP and Controlling it With and Without JMX">Configuring MDP and Controlling it With and Without JMX</a></li><li><a href="http://viralpatel.net/blogs/2008/12/tutorial-struts-spring-framework-example-in-eclipse.html" title="Tutorial:Struts Spring framework example in Eclipse.">Tutorial:Struts Spring framework example in Eclipse.</a></li></ul></div><a href="http://www.facebook.com/share.php?u=http://viralpatel.net/blogs/2010/06/spring-3-mvc-create-hello-world-application-spring-3-mvc.html" target="_blank"><img src="http://img.viralpatel.net/facebook-ico.png" alt="Facebook" border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://twitter.com/home?status=http://viralpatel.net/blogs/2010/06/spring-3-mvc-create-hello-world-application-spring-3-mvc.html target="_blank"><img src="http://img.viralpatel.net/twitter-ico.png" alt="Twitter"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://digg.com/submit?url=http://viralpatel.net/blogs/2010/06/spring-3-mvc-create-hello-world-application-spring-3-mvc.html&amp;title=Spring 3 MVC: Create Hello World application in Spring 3.0 MVC&amp;bodytext=&amp;media=&amp;topic=" target="_blank"><img src="http://img.viralpatel.net/digg-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://reddit.com/submit?url=http://viralpatel.net/blogs/2010/06/spring-3-mvc-create-hello-world-application-spring-3-mvc.html&amp;title=Spring 3 MVC: Create Hello World application in Spring 3.0 MVC" target="_blank"><img src="http://img.viralpatel.net/reddit-ico.png" alt=""  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://www.stumbleupon.com/submit?url=http://viralpatel.net/blogs/2010/06/spring-3-mvc-create-hello-world-application-spring-3-mvc.html&amp;title=Spring 3 MVC: Create Hello World application in Spring 3.0 MVC" target="_blank"><img src="http://img.viralpatel.net/stumble-upon-ico.png" alt="Stumbleupon"  border="0" width="47" height="48"/></a>&nbsp;&nbsp;<a href="http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=http://viralpatel.net/blogs/2010/06/spring-3-mvc-create-hello-world-application-spring-3-mvc.html&amp;title=Spring 3 MVC: Create Hello World application in Spring 3.0 MVC" target="_blank"><img src="http://img.viralpatel.net/delicious-ico.png" alt="Delicious" border="0" width="47" height="48"/></a></div>
<p><a href="http://feedads.g.doubleclick.net/~a/2kv3i5hWTLplnfZodQs_uctRtVo/0/da"><img src="http://feedads.g.doubleclick.net/~a/2kv3i5hWTLplnfZodQs_uctRtVo/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/2kv3i5hWTLplnfZodQs_uctRtVo/1/da"><img src="http://feedads.g.doubleclick.net/~a/2kv3i5hWTLplnfZodQs_uctRtVo/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=Y_Kq28a6wec:00ral0iHj-o:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=Y_Kq28a6wec:00ral0iHj-o:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=Y_Kq28a6wec:00ral0iHj-o:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=Y_Kq28a6wec:00ral0iHj-o:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=Y_Kq28a6wec:00ral0iHj-o:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=Y_Kq28a6wec:00ral0iHj-o:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=Y_Kq28a6wec:00ral0iHj-o:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?i=Y_Kq28a6wec:00ral0iHj-o:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/viralpatelnet?a=Y_Kq28a6wec:00ral0iHj-o:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/viralpatelnet?d=TzevzKxY174" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://viralpatel.net/blogs/2010/06/spring-3-mvc-create-hello-world-application-spring-3-mvc.html/feed</wfw:commentRss>
		<slash:comments>20</slash:comments>
		<feedburner:origLink>http://viralpatel.net/blogs/2010/06/spring-3-mvc-create-hello-world-application-spring-3-mvc.html</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 0.389 seconds. --><!-- Cached page generated by WP-Super-Cache on 2010-09-09 18:28:19 -->
