Question

I am new to struts and as far as i know that .do extension causes the tomcat to call the action servlet and action servlet has resource process object that invokes a particular action class

But lets suppose we have a jsp page

first.jsp

<%@ taglib uri="http://struts.apache.org/tags-html" prefix="s" %>
 <s:form action="myform">... 

when we submit this form

action-mapping in struts.config.xml is called and it picks from there as:

<action input="/first.jsp" name="actionformbean" path="/myform" scope="session"
   type="actionclass"/>

whenever http://....myform.do is encountered, tell the resource process object of the action servlet to invoke actionclass

BUT how is action mapping related to servlet mapping(as url pattern .do is given in here ?)

I am confused with this .do, that how is it appended to the url :(

HELP plz thanks !!

Was it helpful?

Solution

The standard Action Servlet mapping for Struts is defined in your web.xml, the deployment descriptor. It goes like this:

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

The servlet-name is defined earlier in the deployment descriptor:

<servlet>
  <servlet-name>action</servlet-name>
  <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
  <init-param>
     ...
  </init-param>
  <load-on-startup>2</load-on-startup>
  ...
</servlet>

The url-pattern binds all urls ending with .do to the Action Servlet. The Action Servlet in turn delegates all calls to the responsible action.

Now, there are action mappings like the one you mention:

<action input="/first.jsp" name="actionformbean" path="/myform" scope="session"
   type="actionclass"/>

Action mappings have a path that specifies their URL. The URL doesn't need a .do suffix because Struts already "knows" it was called, otherwise the action mapping itself couldn't be executed. Once the specified action is executed, it silently appends a .do suffix since only URL with those suffixes will be matched - otherwise the next request would be lost.

OTHER TIPS

"Thanks for the reply, but you have written that url-pattern binds all urls ending with .do to action servlet. I am still confused is how .do will be appended to the url"

The .do is automatically appended by default by the Struts Frame work(Hope it's been done by ActionServlet itself). If you wish to change the extension(say .abc), then you should modify the action value accordingly (as action="actionsomthing.abcd").

Corrections are appreciated

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top