Extracting Struts 2.0 distribution and installing on tomcat. Extract the downloaded struts distribution struts-2.0.6-all.zip into your favorite directory. To install the struts blank application copy 'struts2-blank-2.0.6' from 'struts-2.0.6-allstruts-2.0.6apps' into the webapps directory of tomcat.
- Struts 2 in Action introduces the Apache Struts 2 web application framework and shows you how to quickly develop professional, production-ready modern web applications. Written by Don Brown, one of the leading developers of Struts 2, Chad Davis, a passionate Struts 2 developer, along with Scott Stanlick, this book gently walks you through the key features of Struts 2 in example-driven, easy-to.
- Net revenues for Q1 were up 8.4% to $60.2 million, earnings before interest and taxes were up 12.2% to $27.3M, EBITDA was up 11.7% to $28.4M and net income was up 10.8% to $16.3M. Arbitron however is in the middle of a battle with Clear Channel which has threatened to take its ratings business elsewhere.
In my previous posts, I have written many examples and tutorials on JAX-RS RESTEasy, Spring 3, Hibernate and other java frameworks e.g. maven or junit. I got many requests to write something on struts 2 also. Well, Here I am starting with hello world example. In next posts, I will try to cover maximum areas and concepts involving struts 2. So, keep watching.
Create maven web project
I will not eat much space here. You can read more details on how to create maven eclipse web project. In short, following commands are used.
Struts 2 dependencies
I am using maven to import struts 2 runtime dependencies. It’s advantage is that you don’t need to remember and hunt for required dependencies manually and you get everything in one shot.
If you want to see what all got included by this, look at below image: (Get the latest version jar files)
web.xml changes
Struts somehow needs to be plugged into your web application. It means that incoming requests to application should be handed over to struts for processing. This is done by adding a filter definition in web.xml file. This filter essentially redirect all incoming requests to StrutsPrepareAndExecuteFilter which then use configurations to handle that request.
Know struts.xml configuration file
So, StrutsPrepareAndExecuteFilter has got an request to handle. Now what? It will use the configuration to know how to handle a particular request. This configuration is defined in struts.xml file. This file will have url mappings specific to application workflow and their action handlers. It also defines the input/success/error views.
Using struts.properties file
Struts uses some default properties to configure its behavior on runtime. You can override these defaults in stuts.properties file.
Writing first action class
This is important step because you will write the actual application logic here. Struts 2 actions usually extend ActionSupport class which provide some methods to override and change the application flow and inject your business logic in between.
Note: Struts 2 actions looks like POJO classes because they have to act as action forms also which were seperate entity in struts 1.
Composing view files
This is general step and involve writing view layer e.g. in our case we are writing jsp files. You can use the message resource to get messages from a property file which help in i18n later.
index.jsp
success.jsp
The message resource file, they are using is:
global.properties
Testing the application
We are good to run our hello world application now. Lets hit the browser.
Type http://localhost:8080/struts2example/ and hit Enter
Press Submit without entering anything
Enter your name and press Submit
That’s all friends for this struts 2 hello world application. If you want to download the source code of this tutorial, follow below given download link.
Happy Learning !!