Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training

Struts 2 Hello World Application Example, Learn how to develop Hello World application in struts 2.

In this section we will develop Hello World application based on Struts 2 Framework.

Ads

Tutorials   
Login form in Struts2 version 2.3.16 Struts 2 Login Application Struts 2 Hello World Annotation Example Struts 2 Tutorial: Easy steps to learn Struts 2 Struts2 Application in Eclipse: Running the application in Eclipse IDE Struts 2 Hello World Application using Eclipse Interceptors in Struts 2 Struts 2 Action Tag Struts 2 in Agile Development Environment Struts 2 UI Tags Generic Tags Creating own Interceptor What are Interceptors in Struts 2 and how do they work? Results Value Stack / OGNL Action in Struts 2 Framework Struts 2 Interceptors Struts 2.3.15.1 Maven - How to use Maven dependency of Struts 2.3.15.1? Download Struts 2.3.15.1 How Struts 2 Framework works? Architecture of Struts 2 Framework Features and Enhancements in Struts 2.3.15.1 Struts 2 Tutorials - Struts version 2.3.15.1 Struts Flow Diagram Step By Step Struts Tutorial Struts 2 Login Form Example Struts 2 Hello World Example Introduction to Struts 2 Framework Downloading and Installing Struts 2.3.8 Struts 2.3.8 released with new features Struts 2.3.8 Tutorials and Examples Subset Tag Actionerror Tag Struts 2 Autocompleter,Struts 2 Autocomplete Generator Tag Struts 2 Application Struts 2 zero configuration,Struts 2 zero configuration Example Static Parameter, Static Parameter in Struts 2, Struts 2 Static Parameter Pagination Example Struts 2.2.1 Title Struts2 ElseIf Tag Example Struts2 Else Tag Example Struts2 If,Else,ElseIf Tag Example Struts2 tag refrences and Example How to download, compile and test the tutorials using ant. Struts 2.1.8 Login Form Struts 2.1.8 Hello World Example Download Struts 2.1.8, Downloading and installing Struts 2.1.8 Showcase application
Ads

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.

       

Advertisements

Ads
Share on Google+Share on Google+

Struts 2 Hello World Application Example, Learn how to develop Hello World application in struts 2.

Posted on: May 21, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Struts 2 Hello World Application Example, Learn how to develop Hello World application in struts 2.   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:3
caw
June 10, 2011
FQWEF

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>
manas jaiswal
June 5, 2012
java

this is not good examlpe that is a poor eaxmple because examlple are not full that only promo so please update the full example of this url so easyly understand the problem that have some one more use that have one line that have more that have like use this eaxmple very fast use that have nothing that h
Israfil
August 25, 2012
ccCxjOadmcfl

When combining a bunch of dojo widegt files with 'requires' statements, it seems that you have to combine them in the 'right' order because processing the require statement causes the file to be loaded separately.I want to cause all the widegt files and their dependent files to be merged into one large file to reduce the number of files that have to be loaded. How do you do that?

Ads

 

Ads