简体   繁体   English

Struts struts-config.xml 动作映射解释

[英]Struts struts-config.xml action-mapping explained

I am a noob to Struts framework.我是 Struts 框架的菜鸟。 I am trying to understand how action-mapping works exactly.我试图了解动作映射究竟是如何工作的。 Suppose I have a JavaScript file that sends an AJAX request:假设我有一个发送 AJAX 请求的 JavaScript 文件:

$("button").click(function(){
    $.ajax({url: "myTestUrl.do", success: function(result){
        //do something with result
    });
});

and my struts-config.xml file looks like this:我的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>

I don't understand the relationship between the action and the form-bean .我不明白actionform-bean之间的关系。 Will my request be handled by TestAction ?我的请求会由TestAction处理吗? If so, what is the purpose of the form bean type attribute?如果是这样,表单 bean type属性的目的是什么?

UPDATE :更新

For anyone who needs a great overview of struts MCV framework check out this link.对于需要对 struts MCV 框架进行全面了解的任何人,请查看链接。

The relationship is made by the name attribute in the action config.该关系由操作配置中的name属性建立。 So if you use name="testForm" then form bean with the name testForm will be injected to the action's execute method.因此,如果您使用name="testForm"则名为testForm表单 bean 将被注入到操作的 execute 方法中。

Your request might be handled if the relative url match the path value in action config and you have mapped the action servlet to *.do in servlet mapping pattern.如果相对 url 与操作配置中的路径值匹配,并且您已将操作 servlet 映射到 servlet 映射模式中的*.do ,则可能会处理您的请求。

The type attribute of the <form-bean> is used to enter FQCN of the bean class that would probably extend the ActionForm . <form-bean>type属性用于输入可能扩展ActionForm的 bean 类的 FQCN。 It's needed by Struts to be able to instantiate a bean when required. Struts 需要它能够在需要时实例化一个 bean。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM