Struts struts-config.xml动作映射说明 [英] Struts struts-config.xml action-mapping explained

查看:104
本文介绍了Struts struts-config.xml动作映射说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Struts框架的菜鸟.我正在尝试了解动作映射的确切工作方式.假设我有一个发送AJAX请求的JavaScript文件:

I am a noob to Struts framework. I am trying to understand how action-mapping works exactly. Suppose I have a JavaScript file that sends an AJAX request:

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

和我的struts-config.xml文件看起来像这样:

and my struts-config.xml file looks like this:

<?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属性的目的是什么?

I don't understand the relationship between the action and the form-bean. Will my request be handled by TestAction? If so, what is the purpose of the form bean type attribute?

更新:

对于需要全面了解Struts MCV框架的任何人,请查看以下链接:

For anyone who needs a great overview of struts MCV framework check out this link: http://www.javaranch.com/journal/2002/03/newslettermar2002.jsp#struts

推荐答案

这种关系是由操作配置中的name属性建立的.因此,如果使用name="testForm",则名称为testForm的form bean将被注入到该动作的execute方法中.

The relationship is made by the name attribute in the action config. So if you use name="testForm" then form bean with the name testForm will be injected to the action's execute method.

如果相对URL与action config中的路径值匹配,并且您已按照servlet映射模式将action servlet映射到*.do,则可能会处理您的请求.

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.

<form-bean>type属性用于输入可能扩展ActionForm的bean类的FQCN. Struts需要它能够在需要时实例化bean.

The type attribute of the <form-bean> is used to enter FQCN of the bean class that would probably extend the ActionForm. It's needed by Struts to be able to instantiate a bean when required.

这篇关于Struts struts-config.xml动作映射说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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