Struts Hello World Example

This is an example of how you can setup a java web project using struts 1 framework
excerpt
In this example, you will use :

tomcat_logo Tomcat Server 7

http://tomcat.apache.org/
Java_Logo Java SDK

http://www.oracle.com/technetwork/java/javase/downloads/index.html
struts Apache Struts

http://struts.apache.org/
project-logo Apache Ant
http://ant.apache.org

Note : Apache Struts 1 has reached its EOL (End of life) at 2013-04-05
http://struts.apache.org/struts1eol-announcement.html

1. Create a java web application. Simply create a folder structure like in the below example
struts-hello-world-structure

2. Java Web Application require you to have a web.xml. So create one inside \webapp\WEB-INF folder

3. Download struts from http://struts.apache.org/download.cgi#struts1310
Most of the time you only require the binary. So you can just click on the link for binary. (approximate 44.5Mb file size)
download_struts

4. Unzip and look for the lib folder
struts_lib_structure

5. Copy all jar files inside lib folder to /webapp/WEB-INF/lib

6. Create a HelloWorldForm.java
Create a HelloWorldForm.java and place in \src\com\justexample\struts\form

7. Create a HelloWorldAction.java
Create a HelloWorldAction.java and place in \src\com\justexample\struts\action

8. Create a HelloWorld.jsp.
Create a HelloWorld.jsp inside /webapp folder.

9. Configure Struts
To tell the struts about your class. Create a struts-config.xml inside /webapp/WEB-INF/

10. Change web.xml
Change web.xml as per following. In this example, ActionServlet will map to *.do (anything end with .do)
The servlet then read configuration from struts-config.xml.

11. Install Tomcat
Download tomcat. Unzip it to c:\tomcat
download_tomcat

12. Create a build.xml
Create a build.xml file and place it in the folder containing src and webapp.
Note : If you do not have ant, try follow the Install Ant in Windows to install one.

13. Compile
Run ant. You should see something like this.
ant_build_struts_hello_world

14. Deploy
Deploy your webapp to tomcat. (Simply copy the webapp folder to C:\tomcat\webapps\

15. Testing
Start your tomcat and open http://localhost:8080/webapp/HelloWorld.do using your browser.
start_tomcat
struts_hello_world_result

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">