如何将.do扩展名附加到struts的URL中? [英] How .do extension is appended in the URL in struts?

查看:78
本文介绍了如何将.do扩展名附加到struts的URL中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Struts的新手,据我所知,.do扩展名导致tomcat调用动作servlet,而动作servlet具有调用特定动作类的资源过程对象.

但是假设我们有一个jsp页面

first.jsp

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

我们提交此表格时

调用struts.config.xml中的

action-mapping,并从那里选择:

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

每当遇到 http://....myform.do 时,告诉资源处理对象servlet调用actionclass的过程

但是操作映射与servlet映射有何关系(如url模式.do在此处给出?)

我对此.do感到困惑,因为它如何附加到url:(

HELP plz 谢谢!

解决方案

用于Struts的标准Action Servlet映射在部署描述符web.xml中定义.它是这样的:

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

该servlet名称是在部署描述符中较早定义的:

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

URL模式将所有以.do结尾的URL绑定到Action Servlet.反过来,动作Servlet将所有调用委派给负责的动作.

现在,有一些动作映射,就像您提到的那样:

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

动作映射具有指定其URL的路径.该URL不需要后缀.do,因为Struts已经知道"了该URL,否则,动作映射本身无法执行.一旦执行了指定的操作,由于仅会匹配带有这些后缀的URL,因此它会静默附加.do后缀-否则下一个请求将丢失.

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

解决方案

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.

这篇关于如何将.do扩展名附加到struts的URL中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆