MappingDispatchAction 学习

简介:
1. MappingDispatchAction的作用域LookupAction的作用差不多相同,但是在应用上稍微有些差别。
 
1.Struts-config.xml
                <action path= "/mapping-invalid"    
                                type= "org.apache.struts.webapp.dispatch.MappingDispatchExampleAction" 
                                parameter= "doInvalid" 
                                name= "testForm" 
                                scope= "request"
                        <exception key= "dispatch.NoSuchMethodException" 
                                             type= "java.lang.NoSuchMethodException" 
                                             path= "/mapping.jsp"/> 
                        <exception key= "dispatch.ServletException" 
                                             type= "javax.servlet.ServletException" 
                                             path= "/mapping.jsp"/> 
                        <forward name= "success" path= "/mapping.jsp"/> 
                </action> 
                <action path= "/mapping-execute"    
                                type= "org.apache.struts.webapp.dispatch.MappingDispatchExampleAction" 
                                parameter= "execute" 
                                name= "testForm" 
                                scope= "request"
                        <exception key= "dispatch.NoSuchMethodException" 
                                             type= "java.lang.NoSuchMethodException" 
                                             path= "/mapping.jsp"/> 
                        <exception key= "dispatch.ServletException" 
                                             type= "javax.servlet.ServletException" 
                                             path= "/mapping.jsp"/> 
                        <forward name= "success" path= "/mapping.jsp"/> 
                </action> 
                <action path= "/mapping-noparam"    
                                type= "org.apache.struts.webapp.dispatch.MappingDispatchExampleAction" 
                                name= "testForm" 
                                scope= "request"
                        <exception key= "dispatch.ServletException" 
                                             type= "javax.servlet.ServletException" 
                                             path= "/mapping.jsp"/> 
                        <forward name= "success" path= "/mapping.jsp"/> 
                </action>
 
主要的工作就是在这里。只不过不同的url 都是指到同一个Action中。使用【parameter】参数来表示不同的url 以访问Action中不同的方法,实现不同的业务逻辑。
 
 
2.然后在JSP 前台页面中,分别提交
    <html:form action= "mapping-foo" style= "display:inline"
                            <html:submit><bean:message key= "button.foo.label" /></html:submit> 
                    </html:form> 
                              
                    <html:form action= "mapping-bar" style= "display:inline"
                            <html:submit><bean:message key= "button.bar.label" /></html:submit> 
                    </html:form> 
                              
                    <html:form action= "mapping-invalid" style= "display:inline"
                            <html:submit><bean:message key= "button.invalid.label" /></html:submit> 
                    </html:form> 
                              
                    <html:form action= "mapping-execute" style= "display:inline"
                            <html:submit><bean:message key= "method.execute.label" /></html:submit> 
                    </html:form> 
                              
                    <html:form action= "mapping-noparam" style= "display:inline"
                            <html:submit><bean:message key= "parameter.missing.label" /></html:submit> 
                    </html:form>
 
这跟表单提交的目标地址,实现访问同一个Action中不同的方法。
 
1、发生的异常 和 LookupDispatcherAction、DispatcherAction的异常一致。



本文转自 randy_shandong 51CTO博客,原文链接:http://blog.51cto.com/dba10g/240832,如需转载请自行联系原作者
相关文章
|
前端开发 Java API
@PathVariable怎么用
@PathVariable怎么用
@RequestParam和@PathVariable的作用
@RequestParam和@PathVariable的作用
271 0
@RequestParam和@PathVariable的作用
Action、RenderAction、Partial、RenderPartial区别
都属于用户控件,Action是直接连接到Action,并且会执行业务逻辑,通过源代码分析可以看出Action最终转换为HTML字符串输出了。并且通过断点调试可以发现Action和RenderAction可进行业务逻辑处理。
1078 0