Sunday, February 8, 2009

Struts 2 Configuration

This blog intends to answer the following questions :-
  1. How to configure a Struts 2 application in web.xml.
In order to make use of the features of Struts 2, one needs to configure the web application to make use of the Struts 2 api. Struts 2 can be used in your web application by adding a simple filter in your web.xml file that takes control of user requests. In the following snippet of the web.xml I demonstrate how this is done.

web.xml
//------Start Of Source Code------
.
.
.
. . . other web.xml elements. . .
.
.
.
<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>
.
.
.
. . . other web.xml elements. . .
.
.
.

//------End Of Source Code------

The Struts filter takes care of all the Struts 2 capabilities by by making use of all the pre-configured Interceptors and performs the DI(Dependency Injection) into the action classes.

So thats all that is required in the deployment descriptor to make your application 'strutified' !!!!

Happy Programming ;)

Signing Off
Ryan

No comments: