web.xml in struts and how it is configured with struts-config.xml

Go To StackoverFlow.com

2

<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

The above code was automatically generated by my IDE when I choose struts framework for my project. I don't see any servlet named action . Please explain what this xml means?

EDIT :

I read that ActionServlet has been configured with the struts-config.xml file. How it is configured ?

<struts-config>

<form-beans>
<form-bean name="HelloWorldActionForm"

type="com.vaannila.HelloWorldActionForm"/>

<action-mappings>
<action input="/index.jsp" name="HelloWorldActionForm" path="/HelloWorld"  scope="session" type="com.vaannila.HelloWorldAction">
<forward name="success" path="/helloWorld.jsp" />
</action>
</action-mappings>
2012-04-04 04:24
by saplingPro


5

The configuration file shown says this:

  • All URLs which end in .do will be processed by a servlet named action
  • The servlet named action corresponds to the class org.apache.struts.action.ActionServlet
2012-04-04 04:28
by Óscar López
I read that ActionServlet has been configured with the struts-config.xml file. can you explain this? see the edi - saplingPro 2012-04-04 04:36
@grassPro The ActionServlet was configured in web.xml, whereas in struts-config.xml the different ActionForms get configured; implicitly these use the ActionServlet - Óscar López 2012-04-04 13:44


3

Here is how Struts works:

Struts has a FrontController. This means all request are going through this controller. This is the org.apache.struts.action.ActionServlet. This class is using the struts-config to pass the request to an other class.

You have specified that everytime the URL: /HelloWorld is request the ActionServlet is passing the request to the class com.vaannila.HelloWorldAction When your class is returning success the ActionServlet will display the jsp: helloWorld.jsp

2012-04-04 04:31
by Adi
Ads