簡體   English   中英

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

我不明白actionform-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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM