HOME | J2ME | Struts | AJAX | SOAP | SOA MEDIA STREAMING AXIS |
Struts for Begginers
Introduction
MVC Design Pattern
Installation
Action Servlets
Hello World
Forms & ActionForms
Messages Resources
Data Bases
Exceptions
Acess ActionForms from JSP
Logic Tag

 

 

Struts for Beginners: Dot do(.do) and Action Servlet

Back | Tutorial Home | Next

Lets investigate the deployment descriptor WEB-INF/web.xml for struts. You will find following xml configurations.

<!-- Standard Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

The above “servlet-mapping” configuration says that what ever request that comes with a mime type .do should go to servlet called “action”. And the servlet “action” is defined in the below configuration. The action is the alias name of the servlet org.apache.struts.action.ActionServlet. This ActionServlet is the Struts controller and extends HTTPServlet class.

<!-- Standard 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>2</load-on-startup>
</servlet>

Any other extension other than .do can be used by configuring accordingly in web.xml.

ActionServlet

Now that your request has reached the ActionServet class. What Next?

ActionServlet performs following tasks

  • As ActionServlet extends HTTPServlet class so it has init() method where WEB-INF/struts-config.xml is loaded. In struts-config we define all the tasks required for respective requests.
  • Processes requests and delegates request handling to RequestProcessor object
  • RequestProcessor delegates these jobs to various Action classes and receives responses from these Action classes and call the respective views. RequestProcessor is not visible to us. This is an internal class used by ActionServlet.

Struts Configuration File “struts-config.xml”

Struts Configuration File defines all the mappings required by a Struts application like controller actions, redirects, resource information, validations, Form Beans, data sources etc. This is the file where the process flow of the Struts application is defined.

Action class is a where the various tasks to be performed for an incoming request are defined. The controller (ActionServlet) will call an Action for each request based on the below action-mappings. Set the following mappings in the struts-config.xml.

<action-mappings>
<action path="/helloWorld" type="com.salsa.HelloWorld">
<forward name="hello" path="/helloWorld.jsp"/>
</action>
</action-mappings>

Back | Tutorial Home | Next

site comments powered by Disqus
Download our free toolbar

toolbar powered by Conduit

| Copyright © 2009. All rights reserved | Terms and Conditions | About | Contact | Feed Back |