![](/img/trans.png)
[英]How action mapping is done with struts with the help of struts-config.xml?
[英]Struts struts-config.xml action-mapping explained
我是 Struts 框架的菜鸟。 我试图了解动作映射究竟是如何工作的。 假设我有一个发送 AJAX 请求的 JavaScript 文件:
$("button").click(function(){
$.ajax({url: "myTestUrl.do", success: function(result){
//do something with result
});
});
我的struts-config.xml
文件如下所示:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<form-beans>
<form-bean name="testForm" type="com.test.TestForm"/>
</form-beans>
<!-- Global Forwards -->
<global-forwards>
</global-forwards>
<!-- Action Mappings -->
<action-mappings>
<action path="/myTestUrl"
type="com.test.TestAction"
name="testForm"
scope="request" />
</action-mappings>
<controller locale="true"/>
</struts-config>
我不明白action
和form-bean
之间的关系。 我的请求会由TestAction
处理吗? 如果是这样,表单 bean type
属性的目的是什么?
更新:
对于需要对 struts MCV 框架进行全面了解的任何人,请查看此链接。
该关系由操作配置中的name
属性建立。 因此,如果您使用name="testForm"
则名为testForm
表单 bean 将被注入到操作的 execute 方法中。
如果相对 url 与操作配置中的路径值匹配,并且您已将操作 servlet 映射到 servlet 映射模式中的*.do
,则可能会处理您的请求。
<form-bean>
的type
属性用于输入可能扩展ActionForm
的 bean 类的 FQCN。 Struts 需要它能够在需要时实例化一个 bean。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.