Java Reference
In-Depth Information
You need to configure the servlet filter in the deployment descriptor, as illustrated in Listing 4-16.
Listing 4-16. web.xml
1.<!DOCTYPE web-app PUBLIC
2. "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
3. " http://java.sun.com/dtd/web-app_2_3.dtd " >
4.
5.<web-app>
6.<display-name>Hello World Struts2 Web App</display-name>
7.<filter>
8.<filter-name>struts2</filter-name>
9.<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
10.</filter>
11.
12.<filter-mapping>
13.<filter-name>struts2</filter-name>
14.<url-pattern>/*</url-pattern>
15.</filter-mapping>
16.</web-app>
Lines 7 to 10 : These lines define the StrutsPrepareAndExecuteFilter that is used
as the servlet filter in Struts 2 to which all URLs are mapped.
Note The FilterDispatcher ( org.apache.struts2.dispatcher.FilterDispatcher ) was used
in early Struts 2 development, and it has been deprecated since Struts 2.1.3.
Listing 4-17 illustrates the struts.xml file.
Listing 4-17. struts.xml
1.<?xml version="1.0" encoding="UTF-8"?>
2.<!DOCTYPE struts PUBLIC
3. "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
4. " http://struts.apache.org/dtds/struts-2.0.dtd " >
5.
6.<struts>
7.<constant name="struts.devMode" value="true" />
8.<package name="basicstruts2" extends="struts-default">
9.<action name="index">
10.<result>/index.jsp</result>
11.</action>
12.</package>
13.</struts>
Lines 9 to 11 : These lines define the index action, which renders the result
index.jsp .
 
 
Search WWH ::




Custom Search