The ActionServlet Class

 < Day Day Up > 



The ActionServlet class is the main controller class that receives all incoming HTTP requests for the application. Additionally, ActionServlet is responsible for initializing the Struts framework for your application. Like any other servlet, ActionServlet must be configured in your application’s Web application deployment descriptor: web.xml. The configuration settings in web.xml specify how to map requests to your Web application to the ActionServlet. There are two ways that ActionServlet can be configured to receive requests in web.xml. First, ActionServlet can be configured using path mapping, as shown here:

<?xml version="1.0"?> <!DOCTYPE web-app PUBLIC   "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"   "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app>   <!-- Action Servlet Configuration -->   <servlet>     <servlet-name>action</servlet-name>     <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>     <init-param>       <param-name>config</param-name>       <param-value>/WEB-INF/struts-config.xml</param-value>     </init-param>     <load-on-startup>1</load-on-startup>   </servlet>   <!-- Action Servlet Mapping -->  <servlet-mapping>     <servlet-name>action</servlet-name>     <url-pattern>/do/*</url-pattern>   </servlet-mapping> </web-app>

Path mapping routes to ActionServlet all requests that match a specified path. The default path is /do/*, as shown in the preceding web.xml file; however, you can use any path that you like.

The second way to map requests to ActionServlet is to use extension mapping, as shown next:

<?xml version="1.0"?> <!DOCTYPE web-app PUBLIC   "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"   "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app>   <!-- Action Servlet Configuration -->   <servlet>     <servlet-name>action</servlet-name>     <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>     <init-param>       <param-name>config</param-name>       <param-value>/WEB-INF/struts-config.xml</param-value>     </init-param>     <load-on-startup>1</load-on-startup>   </servlet>   <!-- Action Servlet Mapping -->   <servlet-mapping>     <servlet-name>action</servlet-name>     <url-pattern>*.do</url-pattern>   </servlet-mapping> </web-app>

Extension mapping maps to ActionServlet all requests with the specified extension. The default extension to use is .do; however, you can use any extension you like.

Note 

Extension mapping is required if you are using Struts’ module feature. For more information on modules, see Chapter 9.



 < Day Day Up > 



Struts. The Complete Reference
Struts: The Complete Reference, 2nd Edition
ISBN: 0072263865
EAN: 2147483647
Year: 2003
Pages: 134
Authors: James Holmes

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net