Services | Updates | Contact
Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML
Search All Tutorials
Top Search: Loan Struts Open Source
Wireless VoIP
The Wifi Wireless VoIP In previous articles, the challenges of security, reliability, VoIP protocol robustness, and voi
 
VoIP Devices
Introduction of VoIP Devices Net2Phone offers a full line of consumer and corporate hardware products for dial-up, br
 
More Tutorials...

Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

 
 
Struts
Comments
 
 

 

Struts 2 Hello World - Developing Hello World Application

                         

In this section we will develop Hello World application based on Struts 2 Framework. Our Struts 2 Hello World application is your first step towards developing applications based on Struts 2 Framework. We are here providing step by step guide for developing Hello World application in Struts 2 framework.

Tutorial covers basic steps like creating directory structure, developing build.xml file to build the application using ant build tool. Then we explained Java, JSP and configuration files that are required in this application.

Creating directory structure for the project

Step1: Extract struts 2 download and copy struts2-blank-2.0.6.war(If you are using latest version of struts 2 then version may be different for you) to your tomcats webapps directory. Rename struts2-blank-2.0.6.war to struts2tutorial and unzip it in the tomcats webapps directory. Now start the tomcat and type http://localhost:8080/struts2tutorial/ into your browser. You browser should show look like:

Congratulations you have successfully installed struts 2 blank application to start with.

Step 2: Now delete the content of struts2tutorial\WEB-INF\src and struts2tutorial\WEB-INF\classes directories, as we don't need these files that comes with struts 2 blank application.

Step 3: Create build.xml file in the struts2tutorial\WEB-INF\src and paste the following content in the build.xml file.

<project name="Struts 2 Tutorial" basedir="../" default="all">
    <!-- Project settings -->
    <property name="project.title" value="RoseIndia Struts 2 Tutorials"/>
	<property name="project.jar.file" value="struts2tutorial.jar"/>

	  <path id="class.path">

		<fileset dir="lib">

		  <include name="**/*.jar"/>

		</fileset>

		<fileset dir="libext">

		  <include name="**/*.jar"/>

		</fileset>

	  </path>

		<!-- Classpath for Project -->

		<path id="compile.classpath">

			<pathelement path ="lib/commons-beanutils.jar"/>

			<pathelement path ="lib/commons-digester.jar"/>

			<pathelement path ="lib/struts.jar"/>

			<pathelement path ="libext/servlet-api.jar"/>

			<pathelement path ="libext/catalina-ant.jar"/>

			<pathelement path ="classes"/>

			<pathelement path ="${classpath}"/>

		</path>

		<!-- Check timestamp on files -->

		<target name="prepare">

			<tstamp/>
			<copy
				file="src/struts.xml"
				todir="src/classes"/>


		</target>
		<!-- Copy any resource or configuration files -->

		<target name="resources">

			<copy todir="src/classes" includeEmptyDirs="no">

				<fileset dir="src/java">

				<patternset>

					<include name="**/*.conf"/>

					<include name="**/*.properties"/>

					<include name="**/*.xml"/>

				</patternset>

				</fileset>

			</copy>

		</target>

		<!-- Normal build of application -->

		<target name="compile" depends="prepare,resources">

			<javac srcdir="src" destdir="src/classes" 
                         debug="true" debuglevel="lines,vars,source">

				<classpath refid="class.path"/>

			</javac>

			<jar

			jarfile="lib/${project.jar.file}"

			basedir="src/classes"/>

		</target>
		<!-- Remove classes directory for clean build -->

		<target name="clean"

		  description="Prepare for clean build">

		  <delete dir="classes"/>

		  <mkdir  dir="classes"/>

		</target>

		<!-- Build Javadoc documentation -->

		<target name="javadoc"

		 description="Generate JavaDoc API docs">

			<delete dir="./doc/api"/>

			<mkdir dir="./doc/api"/>

			<javadoc sourcepath="./src/java"

				destdir="./doc/api"

				classpath="${servlet.jar}:${jdbc20ext.jar}"

				packagenames="*"

				author="true"

				private="true"

				version="true"

				windowtitle="${project.title} API Documentation"

				doctitle="&lt;h1&gt;${project.title}
                          Documentation (Version ${project.version})&lt;/h1&gt;"

				bottom="Copyright &#169; 2002">

				<classpath refid="compile.classpath"/>

			</javadoc>

		</target>

		<!-- Build entire project -->

		<target name="project" depends="clean,prepare,compile"/>

		<!-- Create binary distribution -->

		<target name="dist"

			description="Create binary distribution">

		  <mkdir

			dir="${distpath.project}"/>

		  <jar

			jarfile="${distpath.project}/${project.distname}.jar"

			basedir="./classes"/>

		  <copy

			file="${distpath.project}/${project.distname}.jar"

			todir="${distpath.project}"/>

        

		  <war

			basedir="../"

			warfile="${distpath.project}/${project.distname}.war"

			webxml="web.xml">

			<exclude name="${distpath.project}/${project.distname}.war"/>

		   </war>

    </target>


    <!-- Build project and create distribution-->

	<target name="all" depends="project"/>

        </project>

Step 4: Create directory libext under the struts2tutorial\WEB-INF\ then you copy latest Servlets api jar (in our case servlet-api.jar) file over there. This library file will be used to compile Servlets in our application.

Step 5: Now create directories java and classes under struts2tutorial\WEB-INF\src. The directory struts2tutorial\WEB-INF\src\java will be used to put all the java sources file and directory struts2tutorial\WEB-INF\src\classes will be used by ant build utility to store compiled java files.

Now we have successfully created the directory structure and ant build file for our Struts 2 Hello World Application. In the next section we will create JSP, Java file and the configuration file and then test our Struts 2 Hello World application.

                           
Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

19 comments so far (post your own) View All Comments Latest 10 Comments:

Hi,
when i first tried to run the application i had the following problem.

Struts Problem Report
Struts has detected an unhandled exception:

Messages: There is no Action mapped for action name HelloWorld.

I tried many time and failed. Can somebosy help me resolve this issue.

the problem is with the namespace.

here the namespace defined is 'roseindia' in (struts.xml)

but index.html contains example/HelloWorld.action

changing it to roseindia/HelloWorld.action solved the problem

Regards,
Laxmi narayana

Posted by Laxmi Narayana on Thursday, 04.17.08 @ 22:11pm | #56974

does localization in struts done in entire specification or does it create specific resources for each request?

Posted by jenifer on Wednesday, 03.19.08 @ 12:47pm | #53295

Ashish,

I don't see where this has anything to do the the topic "Ant Build, Struts2 Hello World".

Additionally, why would you want an application written in both jsp and asp. They are not meant to be used together. What are you trying to accomplish.

Posted by Eric Tice on Wednesday, 03.12.08 @ 19:21pm | #52485

I want to down load the all ".jar" files that is needed to run my struts application.From where can i download all the ".jar" files.Give the instructions to me to download the jar files and .tld files

Posted by kranthi on Wednesday, 03.12.08 @ 17:32pm | #52473

please send the usasge code of tiles in struts 2.x

Posted by harinivesh on Thursday, 02.14.08 @ 15:02pm | #48252

Its a good tutorial for the beginners in Struts 2.0

Posted by Vajahat Ali on Monday, 01.28.08 @ 15:22pm | #46396

Hi.
After my tried, I found that it is necessary to copy struts2-core-2.0.XX.jar to lib.
Also need to download the source code and replace the original index.html.

Hope this is useful for the others.

Posted by Kevin on Friday, 01.25.08 @ 15:33pm | #46126

Hi.
After my tried, I found that it is necessary to copy struts2-core-2.0.XX.jar to lib.
Also need to download the source code and replace the original index.html.

Hope this is useful for the others.

Posted by Kevin on Friday, 01.25.08 @ 15:31pm | #46124

Looks like there is something missing in the instructions for installing Struts on Tomact. Apparently from the previous comment, it looks like. Can somebosy point me to the right direction.

Posted by Lakshmi on Sunday, 01.13.08 @ 05:57am | #45086

I am new to struta. I already have Tomcat6 and ant installed on my machine. I dowloaded struts2.0.6. I followed the steps exactly from your website http://www.roseindia.net/struts/struts2/struts-2-hello-world.shtml. I am getting the following message:

Struts Problem Report
Struts has detected an unhandled exception:

Messages: There is no Action mapped for action name HelloWorld.

I tried many time and failed. Can somebosy help me resolve this issue.

Thank You


Posted by Lakshmi on Sunday, 01.13.08 @ 05:20am | #45083

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.