This article explains how you can setup quickly an application based on Struts on JBoss 5 application server.
Install JBoss Struts plugin on Eclipse
For our example we have installed Eclipse IDE for Java Developers (Ganymede) which is the Enterprise Version of Eclipse foundation: check it here:
Once you have extracted Eclipse you need to update your plugins: from the Help Menu, select "Software Updates". In the "Available Software" Click on "Add site" and add JBoss plugins site:
Here there's a whole lot of plugins, however what you need is basically JBoss AS plugin and Struts plugin. Once installed you have to restart Eclipse.
Create the Web project
Create a new Dynamic Web Project from Menu : File | New | Other | Web | Dynamic Web project.
Set the Web module version to 2.5 and choose as Runtime your jBoss Runtime environment.
Now Add Struts capabilities to your project. Right click on it and select:
The Struts wizard will start. The first gui will ask where you have your web.xml file. You can leave the default value.
Next GUI, Project Modules, will add Struts Support to your Project. Click on the Button and select the Struts version and configuation files.
Now your project Modules should be compiled with the correct configuration. Click next.
In the last applet you will basically select the classes/lib path Servlet and Struts version. Select Servlet version 2.5 , Struts 1.2 and leave unchecked the "Add libraries".
Unfortunately I found some incompatibilities with the libraries provided by the Tool so we have to donwload the libraries from Jakarta site.
Download Struts libraries
Download Struts 1.3 libraries from jakarta site:
Unzip the libraries in a folder, such as StrutsLibs
Configure the Project to use Struts libraries
Configuring your project to use Struts libraries by right-clicking on the Project and selecting "Properties". Configure the build-path by adding all libraries except commons-logging.jar which is already loaded by JBoss.
The libraries you have selected needs to be added also in the WEB-INF/lib folder. You can do this by selecting again Project properties | Java EE Module Dependancies.
Check all Struts libraries and Click Ok.
Add Struts Components
Following is a sample Struts application which we have used to test Struts on JBoss.
The configuration file struts-config.xml contains basically one Action named com.sample.LoginAction , one FormBean named com.sample.LoginFormBean and three jsp: login.jsp, welcome.jsp and error.jsp.
This is how our configuration looks like from the Diagram view:
This is our login.jsp page:
The login.jsp is backed by a LoginFormBean which contains the mapping for the corresponding fields:
Notice this class uses a Validator to check the validity of the fields. You have to add a file named ApplicationResources.properties in the folder com.sample
username.error=username cannot be null
password.error=Password cannot be null
Last piece of code is the LogicAction which demandates the logic for logging in to an external DAO class....(which you have to implement)
That's all. Add two landing pages welcome.jsp and error.jsp and deploy your application. If you have deployed your application as StrutsExample.war then you can access to it with: http://localhost:8080/StrutsExample/login.jsp
Have fun with JBoss and Struts !
Click here to download the code<