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,如需转载请自行联系原作者
相关文章
|
8月前
|
JavaScript
原生js中offsetTop, offsetLeft与offsetParent的详细讲解
原生js中offsetTop, offsetLeft与offsetParent的详细讲解
|
JavaScript
preventDefault 和 stopPropagation 的区别
版权声明:本文首发 http://asing1elife.com ,转载请注明出处。 https://blog.csdn.net/asing1elife/article/details/82620083 ...
2444 0
|
Java Android开发
Android项目实战(一): SpannableString与SpannableStringBuilder
原文:Android项目实战(一): SpannableString与SpannableStringBuilder 前言: 曾经在一些APP中的一些类似“帮助”“关于”的界面看过一行文字显示不同的颜色的效果,如下效果: 本软件是一款高、大、上的社区类软件。
1199 0