I am assuming that you have already installed ant build tool on your machine. Since we are using the ant built tool to build the application. To build the application open command prompt and go to "struts2helloworld\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 "struts2tutorial.jar" into the lib directory of your web application. Here is the output of ant build tool:
| C:\sourcecontrol\code\roseindiacodes\struts2\struts2helloworld\WEB-INF\src>ant Buildfile: build.xml clean: [delete] Deleting directory C:\sourcecontrol\code\roseindiacodes\struts2\struts2helloworld\WEB-INF\classes [mkdir] Created dir: C:\sourcecontrol\code\roseindiacodes\struts2\struts2helloworld\WEB-INF\classes prepare: resources: compile: [javac] Compiling 1 source file to C:\sourcecontrol\code\roseindiacodes\struts2\struts2helloworld\WEB-INF\src\classes [jar] Building jar: C:\sourcecontrol\code\roseindiacodes\struts2\struts2helloworld\WEB-INF\lib\struts2tutorial.jar project: all: BUILD SUCCESSFUL Total time: 19 seconds C:\sourcecontrol\code\roseindiacodes\struts2\struts2helloworld\WEB-INF\src> |
Testing Struts 2 Hello World Application
In the above section we have compiled our application and now finally we will test our application. To test the application start the tomcat server and type http://localhost:8080/struts2HelloWorldApplication/ and then select "Run Struts 2 Hello World Application" from the list.
Here is the output of struts 2 Hello World Application:
When run this application you get:

After clicking on the "Run Struts 2 Hello World Application" Then you get the message "Struts 2 Hello World Application" on the screen.

How application works?
Here is the brief description on how Struts 2 Hello World Application works:
Your browser sends a request to the web
server for the URL http://localhost:8080/struts2HelloWorldApplication/roseindia/HelloWorld.action
Here is the configuration from web.xml file:
|
<?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>Struts Blank</display-name> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app> |
Download "Hello World" Application
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Deploying Struts and testing struts 2 hello world application View All Comments
Post your Comment