176 CHAPTER 4: Building a Web Application Using Struts 2
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
- "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
- "http://java.sun.com/dtd/web-app_2_3.dtd" >
5.
6.Hello World Struts2 Web App
7.
8.struts2
9.org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
10.
12.
13.struts2
14./*
15.
16.
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
- "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
- "http://struts.apache.org/dtds/struts-2.0.dtd">
6.
7.
8.
9.
10./index.jsp
11.
12.
13.
Lines 9 to 11: These lines define the index action, which renders the result
index.jsp.