saplingPro
saplingPro

Reputation: 21329

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

<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>

Upvotes: 2

Views: 16759

Answers (3)

SivaStack
SivaStack

Reputation: 11

By default ActionServlet is configured to /WEB-INF/struts-config.xml file under your web application project directory.

for example: if your project name is StrutsPractice then you can find the default configuration file in the path /StrutsPractice/src/main/webapp/WEB-INF/struts-config.xml

To explicitly configure the ActionServlet or you want to configure it to a config file in a different path then you can configure it like below in web.xml

<servlet>
    <servlet-name>strutspractice</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>

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

Upvotes: 0

Adi
Adi

Reputation: 140

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

Upvotes: 3

&#211;scar L&#243;pez
&#211;scar L&#243;pez

Reputation: 236004

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

Upvotes: 5

Related Questions