`

struts中的DispatchAction、LookupDispatchAction、Mappin

阅读更多
转载:http://hi.baidu.com/javajavajava/blog
index.jsp

<%@ page language="java" pageEncoding="GB18030"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
<head>
<html:base />
<title>index.jsp</title>
</head>

<body>
DispatchAction
<ul>
    <li><html:link page="/testDispatch.do?method=a">testDispatch a</html:link></li>
    <li><html:link page="/testDispatch.do?method=b">testDispatch b</html:link></li>
    <li><html:link page="/testDispatch.do?method=c">testDispatch c</html:link></li>
</ul>
LookupDispatchAction
<ul>
    <li>
     <html:form action="/testLookupDispatch.do">
     <html:submit property="cmd"><bean:message key="button.a"/></html:submit>
     <html:submit property="cmd"><bean:message key="button.b"/></html:submit>
     </html:form>
    </li>
</ul>
MappingDispatchAction
<ul>
    <li><html:link page="/a.do">MappingDispatchAction a</html:link></li>
    <li><html:link page="/b.do">MappingDispatchAction b</html:link></li>
</ul>
</body>
</html:html>


struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">

<struts-config>
     <data-sources />
     <form-beans >
       <form-bean name="testDispatchForm" type="com.hqh.struts.form.TestDispatchForm" />
       <form-bean name="testLookupDispatchForm" type="com.hqh.struts.form.TestLookupDispatchForm" />
       <form-bean name="testMappingDispatchForm" type="com.hqh.struts.form.TestMappingDispatchForm" />

     </form-beans>

     <global-exceptions />
     <global-forwards />
     <action-mappings >
       <action
         attribute="testDispatchForm"
         input="/index.jsp"
         name="testDispatchForm"
         parameter="method"
         path="/testDispatch"
         scope="request"
         type="com.hqh.struts.action.TestDispatchAction" />
       <action
         attribute="testLookupDispatchForm"
         input="/index.jsp"
         name="testLookupDispatchForm"
         parameter="cmd"
         path="/testLookupDispatch"
         scope="request"
         type="com.hqh.struts.action.TestLookupDispatchAction" />
       <action
         attribute="testMappingDispatchForm"
         input="/index.jsp"
         name="testMappingDispatchForm"
        parameter="a"
         path="/a"
         scope="request"
         type="com.hqh.struts.action.TestMappingDispatchAction" />
       <action
         attribute="testMappingDispatchForm"
         input="/index.jsp"
         name="testMappingDispatchForm"
        parameter="b"
         path="/b"
         scope="request"
         type="com.hqh.struts.action.TestMappingDispatchAction" />

     </action-mappings>

     <message-resources parameter="com.hqh.struts.ApplicationResources" />
</struts-config>

TestDispatchAction.java

/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.hqh.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.hqh.struts.form.TestDispatchForm;

/** 
* MyEclipse Struts
* Creation date: 09-30-2007
* 
* XDoclet definition:
* @struts.action path="/testDispatch" name="testDispatchForm" input="/form/testDispatch.jsp" parameter="method" scope="request" validate="true"
*/
public class TestDispatchAction extends DispatchAction {
/*
     * Generated Methods
     */

/** 
     * Method execute
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return ActionForward
     */
public ActionForward a(ActionMapping mapping, ActionForm form,
      HttpServletRequest request, HttpServletResponse response) {
     TestDispatchForm testDispatchForm = (TestDispatchForm) form;
     System.out.println("TestDispatchAction-->a");
     return null;
}
public ActionForward b(ActionMapping mapping, ActionForm form,
      HttpServletRequest request, HttpServletResponse response) {
     TestDispatchForm testDispatchForm = (TestDispatchForm) form;
     System.out.println("TestDispatchAction-->b");
     return null;
}
public ActionForward c(ActionMapping mapping, ActionForm form,
      HttpServletRequest request, HttpServletResponse response) {
     TestDispatchForm testDispatchForm = (TestDispatchForm) form;
     System.out.println("TestDispatchAction-->c");
     return null;
}
}

TestLookupDispatchAction.java

/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.hqh.struts.action;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.LookupDispatchAction;

import com.hqh.struts.form.TestLookupDispatchForm;

/** 
* MyEclipse Struts
* Creation date: 09-30-2007
* 
* XDoclet definition:
* @struts.action path="/testLookupDispatch" name="testLookupDispatchForm" input="/form/testLookupDispatch.jsp" parameter="cmd" scope="request" validate="true"
*/
public class TestLookupDispatchAction extends LookupDispatchAction {
/*
     * Generated Methods
     */
public ActionForward a(ActionMapping mapping, ActionForm form,
      HttpServletRequest request, HttpServletResponse response) {
     TestLookupDispatchForm testLookupDispatchForm = (TestLookupDispatchForm) form;
     System.out.println("TestLookupDispatchAction--a");
     return null;
}
public ActionForward b(ActionMapping mapping, ActionForm form,
      HttpServletRequest request, HttpServletResponse response) {
     TestLookupDispatchForm testLookupDispatchForm = (TestLookupDispatchForm) form;
     System.out.println("TestLookupDispatchAction--b");
     return null;
}

@Override
protected Map getKeyMethodMap() {
     Map map = new HashMap();
     map.put("button.a", "a");
     map.put("button.b", "b");
     return map;
}
}

TestMappingDispatchAction.java

/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.hqh.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.MappingDispatchAction;
import com.hqh.struts.form.TestMappingDispatchForm;

/** 
* MyEclipse Struts
* Creation date: 09-30-2007
* 
* XDoclet definition:
* @struts.action path="/testMappingDispatch" name="testMappingDispatchForm" input="/form/testMappingDispatch.jsp" parameter="a" scope="request" validate="true"
*/
public class TestMappingDispatchAction extends MappingDispatchAction {
/*
     * Generated Methods
     */
public ActionForward a(ActionMapping mapping, ActionForm form,
      HttpServletRequest request, HttpServletResponse response) {
     TestMappingDispatchForm testMappingDispatchForm = (TestMappingDispatchForm) form;
     System.out.println("TestMappingDispatchAction-->a");
     return null;
}
public ActionForward b(ActionMapping mapping, ActionForm form,
      HttpServletRequest request, HttpServletResponse response) {
     TestMappingDispatchForm testMappingDispatchForm = (TestMappingDispatchForm) form;
     System.out.println("TestMappingDispatchAction-->b");
     return null;
}
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics