Sun Java Struts Tutorial
Sun's Java programming language is one of the most popular programming languages. It has a wide adoption for server-side development for web applications. Apache Struts is an open-source Java framework that helps creation of web based applications. It provides a Model-View-Controller architecture that streamlines the development of web based applications by demarcating code into Model--representing business data, View--representing page design and Controller--representing page navigation logic. It also provides a library of tag library that offers functionality frequently needed in a web application.
Things You'll Need
- Apache struts library java archive (jar) file
- Web container like Apache Tomcat
- Java Integrated Development Environment (IDE) like NetBeans
- Any dependent library jar files
Instructions
-
Setting up the development environment
-
1
Download Struts jar file from http://struts.apache.org/download.cgi
-
2
Add the struts jar file to your project's library path. This will make the Struts classes available for your application development.
-
-
3
Download and install the web container (example Apache Tomcat) to be used in deploying the Apache Struts application.
Developing the application
-
4
Model your application as a series of Forms that are sent to an action which direct the user to result (success or error) pages.
-
5
Design your web application and assemble the static pages and forms like java server pages and HTML pages in the project. Example: createUser.jsp.
-
6
Develop the model and action classes that will be used in the application. Example: UserAction.java, User.java
-
7
Develop the view pages like the success and error pages that will get used in the application. Example: UserCreated.jsp, UserError.jsp
Deploy the application
-
8
Configure the web.xml file and define the Servlets and Struts actions that were developed in Section 2. A sample action will consist of web form page (from Section 2, Step2) that gets submitted to an action (Section 2, Step 3) which in turn directs the user to a success or error page (Section 2, Step 4).
-
9
(optional) Bundle the application into a web archive (war) file. The files can also be deployed directly as an expanded application.
-
10
Deploy the application files or the war file created in Step 2 above onto the web container being used (example tomcat). Make sure all the application classes and library jar files are deployed correctly.
-
11
Access and test your Java Struts application.
-
1
Tips & Warnings
It is a good idea to go through the Struts tag library to re-use pre-built web application logic and form elements.
Make sure all the necessary the library jar files are copied to the development environment as well as the deployment environment.
References
Resources
- Photo Credit pagina web image by Bernardo Varela from Fotolia.com