![](/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.