How .do extension is appended in the URL in struts?

為{幸葍}努か 提交于 2019-12-05 20:04:47

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.

binaries01

"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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!