Serdar Alkan
Serdar Alkan

Reputation: 161

What is the difference of path type in struts-config.xml?

I am new Java Struts 1 framework. But I want to ask a question.

In struts-config.xml path value ends with .do like this "/AddReq.do", or path value is only action name like this "AddReq"?

What is difference between "/AddReq.do" and "AddReq" ?

For example:

<action path="/AddReqPage"
type="...actions.AddReqPageAction">
        <forward name="success" path="AddReq" /> 
        <forward name="failure" path="/bos.jsp" />
</action>
<action path="/AddReq"
type="...actions.AddReqAction"
name="AddReqForm" validate="true"
scope="request">
        <forward name="success" path="/AddReqDetail.do" />
        <forward name="hata" path="AddReq" />
        <forward name="failure" path="/bos.jsp" />
</action>

Upvotes: 2

Views: 847

Answers (2)

anoopelias
anoopelias

Reputation: 9548

Not much difference. Both should work - provided you map to Struts ActionServlet correctly in your web.xml.

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

Conventionally, Struts uses *.do pattern to distingush its servlet from other servlets and JSPs.

Upvotes: 4

Roman C
Roman C

Reputation: 1

.do is an action extension. You configure it using the servlet-mapping in web.xml.

When Struts parses the URL, it's looking for such extension to distinguish other requests from the Struts action.

Then it finds the mapping that corresponds to that URL, but without .do.

However, you have still specify .do in the forwards if your application is configured to use that extension.

Nowadays, this extension has less meaning as before. The URL rewrite technique brings us a way to completely ignore that extension.

Using this mapping in web.xml:

<servlet-mapping>
  <servlet-name>action</servlet-name>
  <url-pattern>/c/*</url-pattern>
</servlet-mapping>

and reference above you could completely dismiss it.

Upvotes: 1

Related Questions