Magazine
 
Struts2

<?xml version=”1.0" encoding=”UTF-8" ?>
<!DOCTYPE struts PUBLIC
“-//Apache Software Foundation//DTD Struts
Configuration 2.0//EN”
“http://struts.apache.org/dtds/struts-
2.0.dtd”>
<struts>
<constant
name=”struts.enable.DynamicMethodInvocation”
value=”false” />
<constant name=”struts.devMode”
value=”true” />
<package name=”javajazzup” namespace=”/
javajazzup “ extends=”struts-default”>
<action name=”HelloWorld”
class=”net.javajazzup.Struts2HelloWorld”>
<result>/pages/HelloWorld.jsp</result>
</action>
<!— Add actions here —>
</package>
<!— Add packages here —>
</struts>

The struts.xml file should be present in the class path of the application. You can either include it in the jar and place in the lib directory of the application or place it in the classes directory of the web application. In our application we are using ant build tool, which is including it in the jar file. 

Building the application

I am assuming that you have already installed ant build tool on your machine. Since we are using the ant built tool, the building the application is very easy. To build the application open command prompt and go to “ struts2example\WEB-INF\src” directory of the web application and issue the “ant” command. The ant build tool will compile the java file and create jar file “ struts2example.jar” into the lib directory of your web application. Here is the
output of ant build tool:

 

C:\apache-tomcat-
5.5.23\webapps\struts2example\WEBINF\
src>ant
Buildfile: build.xml
clean:
[delete] Deleting directory C:\apachetomcat-
5.5.23\webapps\struts2example\WE
B-INF\classes
[mkdir] Created dir: C:\apache-tomcat-
5.5.23\webapps\struts2example\WEB-INF\
classes
prepare:
resources:
compile:
[javac] Compiling 1 source file to C:\apachetomcat-
5.5.23\webapps\struts2ex
ample\WEB-INF\src\classes
[jar] Building jar: C:\apache-tomcat-
5.5.23\webapps\struts2example\WEB-INF
\lib\struts2example.jar
project:
all:
BUILD SUCCESSFUL
Total time: 4 seconds
C:\apache-tomcat-
5.5.23\webapps\struts2example\WEBINF\
src>

Testing the application

To test the application start the tomcat server and type http://localhost:8080/struts2example/javajazzup/HelloWorld.action in address bar and hit enter. It will display the
following figure:



Nov 2007 | Java Jazz Up | 35
 
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69   Download PDF