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的异常一致。

你可能感兴趣的:(struts,职场,休闲)