`
gstarwd
  • 浏览: 1524961 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

一个Action对应多个Form DispatchAction

阅读更多

一个Action对应多个Form

关键字: action form

  Action:

 

Java代码 <embed type="application/x-shockwave-flash" width="14" height="15" src="http://awp.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" flashvars="clipboard=package%20com.awp.test.action%3B%0A%0Aimport%20javax.servlet.http.HttpServletRequest%3B%0Aimport%20javax.servlet.http.HttpServletResponse%3B%0A%0Aimport%20org.apache.struts.action.ActionForm%3B%0Aimport%20org.apache.struts.action.ActionForward%3B%0Aimport%20org.apache.struts.action.ActionMapping%3B%0Aimport%20org.apache.struts.actions.DispatchAction%3B%0A%0Aimport%20com.awp.test.form.FirstForm%3B%0Aimport%20com.awp.test.form.SecondForm%3B%0A%0A%2F**%0A%20*%20%40version%201.0%0A%20*%20%40author%20awp%0A%20*%20%40date%202009-4-24%20%E4%B8%8A%E5%8D%8811%3A25%3A49%0A%20*%20%40decription%20%E4%B8%80%E4%B8%AAAction%E4%B8%AD%E5%8C%85%E5%90%AB%E5%A4%9A%E4%B8%AAForm%20%0A%20*%2F%0Apublic%20class%20MultiFormTestAction%20extends%20DispatchAction%20%7B%0A%0A%09%2F**%0A%09%20*%20%E7%AC%AC%E4%B8%80%E4%B8%AAForm%E5%AF%B9%E5%BA%94%E6%96%B9%E6%B3%95%0A%09%20*%2F%20%0A%09public%20ActionForward%20firstForm(ActionMapping%20mapping%2C%20ActionForm%20form%2C%0A%09%09%09HttpServletRequest%20request%2C%20HttpServletResponse%20response)%7B%0A%09%09%09FirstForm%09beanform%09%3D%09(FirstForm)form%3B%0A%09%09%09request.setAttribute(%22name%22%2C%20beanform.getName())%3B%0A%09%09%09return%20mapping.findForward(%22display%22)%3B%0A%09%7D%0A%09%2F**%0A%09%20*%20%20%E7%AC%AC%E4%BA%8C%E4%B8%AAForm%E5%AF%B9%E5%BA%94%E6%96%B9%E6%B3%95%0A%09%20*%2F%20%0A%09public%20ActionForward%20secondForm(ActionMapping%20mapping%2C%20ActionForm%20form%2C%0A%09%09%09HttpServletRequest%20request%2C%20HttpServletResponse%20response)%7B%0A%09%09%09SecondForm%09beanform%09%3D%09(SecondForm)form%3B%0A%09%09%09request.setAttribute(%22name%22%2C%20beanform.getName())%3B%0A%09%09%09return%20mapping.findForward(%22display%22)%3B%0A%09%7D%0A%7D%0A" quality="high" allowscriptaccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>
  1. package  com.awp.test.action;  
  2.   
  3. import  javax.servlet.http.HttpServletRequest;  
  4. import  javax.servlet.http.HttpServletResponse;  
  5.   
  6. import  org.apache.struts.action.ActionForm;  
  7. import  org.apache.struts.action.ActionForward;  
  8. import  org.apache.struts.action.ActionMapping;  
  9. import  org.apache.struts.actions.DispatchAction;  
  10.   
  11. import  com.awp.test.form.FirstForm;  
  12. import  com.awp.test.form.SecondForm;  
  13.   
  14. /**  
  15.  * @version 1.0  
  16.  * @author awp  
  17.  * @date 2009-4-24 上午11:25:49  
  18.  * @decription 一个Action中包含多个Form   
  19.  */   
  20. public   class  MultiFormTestAction  extends  DispatchAction {  
  21.   
  22.     /**  
  23.      * 第一个Form对应方法  
  24.      */    
  25.     public  ActionForward firstForm(ActionMapping mapping, ActionForm form,  
  26.             HttpServletRequest request, HttpServletResponse response){  
  27.             FirstForm   beanform    =   (FirstForm)form;  
  28.             request.setAttribute("name" , beanform.getName());  
  29.             return  mapping.findForward( "display" );  
  30.     }  
  31.     /**  
  32.      *  第二个Form对应方法  
  33.      */    
  34.     public  ActionForward secondForm(ActionMapping mapping, ActionForm form,  
  35.             HttpServletRequest request, HttpServletResponse response){  
  36.             SecondForm  beanform    =   (SecondForm)form;  
  37.             request.setAttribute("name" , beanform.getName());  
  38.             return  mapping.findForward( "display" );  
  39.     }  
  40. }  
package com.awp.test.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.awp.test.form.FirstForm;
import com.awp.test.form.SecondForm;

/**
 * @version 1.0
 * @author awp
 * @date 2009-4-24 上午11:25:49
 * @decription 一个Action中包含多个Form 
 */
public class MultiFormTestAction extends DispatchAction {

	/**
	 * 第一个Form对应方法
	 */ 
	public ActionForward firstForm(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){
			FirstForm	beanform	=	(FirstForm)form;
			request.setAttribute("name", beanform.getName());
			return mapping.findForward("display");
	}
	/**
	 *  第二个Form对应方法
	 */ 
	public ActionForward secondForm(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){
			SecondForm	beanform	=	(SecondForm)form;
			request.setAttribute("name", beanform.getName());
			return mapping.findForward("display");
	}
}

 

 

Form:

Java代码 <embed type="application/x-shockwave-flash" width="14" height="15" src="http://awp.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" flashvars="clipboard=package%20com.awp.test.form%3B%0A%0Aimport%20org.apache.struts.action.ActionForm%3B%0A%0Apublic%20class%20FirstForm%20extends%20ActionForm%20%7B%0A%0A%09private%20String%09name%3B%0A%0A%09public%20String%20getName()%20%7B%0A%09%09return%20name%3B%0A%09%7D%0A%0A%09public%20void%20setName(String%20name)%20%7B%0A%09%09this.name%20%3D%20name%3B%0A%09%7D%0A%0A%7D" quality="high" allowscriptaccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>
  1. package  com.awp.test.form;  
  2.   
  3. import  org.apache.struts.action.ActionForm;  
  4.   
  5. public   class  FirstForm  extends  ActionForm {  
  6.   
  7.     private  String  name;  
  8.   
  9.     public  String getName() {  
  10.         return  name;  
  11.     }  
  12.   
  13.     public   void  setName(String name) {  
  14.         this .name = name;  
  15.     }  
  16.   
  17. }  
package com.awp.test.form;

import org.apache.struts.action.ActionForm;

public class FirstForm extends ActionForm {

	private String	name;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

}

 

Java代码 <embed type="application/x-shockwave-flash" width="14" height="15" src="http://awp.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" flashvars="clipboard=package%20com.awp.test.form%3B%0A%0Aimport%20org.apache.struts.action.ActionForm%3B%0A%0Apublic%20class%20SecondForm%20extends%20ActionForm%20%7B%0A%0A%09private%20String%09name%3B%0A%0A%09public%20String%20getName()%20%7B%0A%09%09return%20name%3B%0A%09%7D%0A%0A%09public%20void%20setName(String%20name)%20%7B%0A%09%09this.name%20%3D%20name%3B%0A%09%7D%0A%0A%7D" quality="high" allowscriptaccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>
  1. package  com.awp.test.form;  
  2.   
  3. import  org.apache.struts.action.ActionForm;  
  4.   
  5. public   class  SecondForm  extends  ActionForm {  
  6.   
  7.     private  String  name;  
  8.   
  9.     public  String getName() {  
  10.         return  name;  
  11.     }  
  12.   
  13.     public   void  setName(String name) {  
  14.         this .name = name;  
  15.     }  
  16.   
  17. }  
package com.awp.test.form;

import org.apache.struts.action.ActionForm;

public class SecondForm extends ActionForm {

	private String	name;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

}

 

 struts-cofing.xml

 

Xml代码 <embed type="application/x-shockwave-flash" width="14" height="15" src="http://awp.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" flashvars="clipboard=%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%0A%3C!DOCTYPE%20struts-config%20PUBLIC%20%22-%2F%2FApache%20Software%20Foundation%2F%2FDTD%20Struts%20Configuration%201.1%2F%2FEN%22%20%0A%22http%3A%2F%2Fjakarta.apache.org%2Fstruts%2Fdtds%2Fstruts-config_1_1.dtd%22%3E%0A%3Cstruts-config%3E%0A%09%3Cform-beans%3E%0A%09%09%3Cform-bean%20name%3D%22firstform%22%20type%3D%22com.awp.test.form.FirstForm%22%2F%3E%0A%09%09%3Cform-bean%20name%3D%22secondform%22%20type%3D%22com.awp.test.form.SecondForm%22%2F%3E%0A%09%3C%2Fform-beans%3E%0A%09%3Cglobal-forwards%3E%0A%09%09%3Cforward%20name%3D%22display%22%20path%3D%22%2Fdisplay.jsp%22%2F%3E%0A%09%3C%2Fglobal-forwards%3E%0A%09%3Caction-mappings%3E%0A%09%09%3Caction%20path%3D%22%2Ffirstpath%22%0A%09%09%09%09input%3D%22%2Ffirst.jsp%22%0A%09%09%09%09name%3D%22firstform%22%0A%09%09%09%09parameter%3D%22method%22%0A%09%09%09%09scope%3D%22request%22%0A%09%09%09%09type%3D%22com.awp.test.action.MultiFormTestAction%22%2F%3E%0A%09%09%09%09%0A%09%09%3Caction%20path%3D%22%2Fsecondpath%22%0A%09%09%09%09input%3D%22%2Fsecond.jsp%22%0A%09%09%09%09name%3D%22secondform%22%0A%09%09%09%09parameter%3D%22method%22%0A%09%09%09%09scope%3D%22request%22%0A%09%09%09%09type%3D%22com.awp.test.action.MultiFormTestAction%22%2F%3E%09%09%09%09%0A%09%3C%2Faction-mappings%3E%0A%09%3Cmessage-resources%20parameter%3D%22MessageResources%22%20%2F%3E%20%0A%3C%2Fstruts-config%3E%0A%0A" quality="high" allowscriptaccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>
  1. <? xml   version = "1.0"   encoding = "UTF-8" ?>   
  2. <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"   
  3. "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd " >   
  4. < struts-config >   
  5.     < form-beans >   
  6.         < form-bean   name = "firstform"   type = "com.awp.test.form.FirstForm" />   
  7.         < form-bean   name = "secondform"   type = "com.awp.test.form.SecondForm" />   
  8.     </ form-beans >   
  9.     < global-forwards >   
  10.         < forward   name = "display"   path = "/display.jsp" />   
  11.     </ global-forwards >   
  12.     < action-mappings >   
  13.         < action   path = "/firstpath"   
  14.                 input = "/first.jsp"   
  15.                 name = "firstform"   
  16.                 parameter = "method"   
  17.                 scope = "request"   
  18.                 type = "com.awp.test.action.MultiFormTestAction" />   
  19.                   
  20.         < action   path = "/secondpath"   
  21.                 input = "/second.jsp"   
  22.                 name = "secondform"   
  23.                 parameter = "method"   
  24.                 scope = "request"   
  25.                 type = "com.awp.test.action.MultiFormTestAction" />                 
  26.     </ action-mappings >   
  27.     < message-resources   parameter = "MessageResources"   />    
  28. </ struts-config >   
<?xml version="1.0" encoding="UTF-8"?>
<!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="firstform" type="com.awp.test.form.FirstForm"/>
		<form-bean name="secondform" type="com.awp.test.form.SecondForm"/>
	</form-beans>
	<global-forwards>
		<forward name="display" path="/display.jsp"/>
	</global-forwards>
	<action-mappings>
		<action path="/firstpath"
				input="/first.jsp"
				name="firstform"
				parameter="method"
				scope="request"
				type="com.awp.test.action.MultiFormTestAction"/>
				
		<action path="/secondpath"
				input="/second.jsp"
				name="secondform"
				parameter="method"
				scope="request"
				type="com.awp.test.action.MultiFormTestAction"/>				
	</action-mappings>
	<message-resources parameter="MessageResources" /> 
</struts-config>

 

first.jsp

Html代码 <embed type="application/x-shockwave-flash" width="14" height="15" src="http://awp.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" flashvars="clipboard=%3C%25%40%20page%20language%3D%22java%22%20pageEncoding%3D%22UTF-8%22%25%3E%0A%3C!doctype%20html%20public%20%22-%2F%2FW3C%2F%2FDTD%20XHTML%201.0%20Transitional%2F%2FEN%22%20%0A%22http%3A%2F%2Fwww.w3.org%2FTR%2Fxhtml1%2FDTD%2Fxhtml1-transitional.dtd%22%3E%0A%3Chtml%3E%0A%20%20%3Chead%3E%0A%20%20%20%20%3Ctitle%3E%E6%88%91%E6%98%AF%E6%8F%90%E4%BA%A4%E7%AC%AC%E4%B8%80%E4%B8%AAFORM%E7%9A%84%E9%A1%B5%E9%9D%A2%3C%2Ftitle%3E%0A%20%20%3C%2Fhead%3E%0A%20%20%3Cbody%3E%0A%20%20%20%3Cform%20action%3D%22%3C%25%3Drequest.getContextPath()%25%3E%2Ffirstpath.do%3Fmethod%3DfirstForm%22%20method%3D%22post%22%3E%0A%20%20%20%09%3Cinput%20name%3D%22name%22%20value%3D%22%22%20type%3D%22text%22%2F%3E%0A%20%20%20%09%3Cinput%20name%3D%22ok%22%20value%3D%22%E6%8F%90%E4%BA%A4%22%20type%3D%22submit%22%2F%3E%0A%20%20%20%3C%2Fform%3E%0A%20%20%3C%2Fbody%3E%0A%3C%2Fhtml%3E%0A" quality="high" allowscriptaccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>
  1. < %@ page  language = "java"   pageEncoding = "UTF-8" % >   
  2. <!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN"   
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >   
  4. < html >   
  5.   < head >   
  6.     < title > 我是提交第一个FORM的页面 </ title >   
  7.   </ head >   
  8.   < body >   
  9.    < form   action = "<%=request.getContextPath()%>/firstpath.do?method=firstForm"   method = "post" >   
  10.     < input   name = "name"   value = ""   type = "text" />   
  11.     < input   name = "ok"   value = "提交"   type = "submit" />   
  12.    </ form >   
  13.   </ body >   
  14. </ html >   
<%@ page language="java" pageEncoding="UTF-8"%>
<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>我是提交第一个FORM的页面</title>
  </head>
  <body>
   <form action="<%=request.getContextPath()%>/firstpath.do?method=firstForm" method="post">
   	<input name="name" value="" type="text"/>
   	<input name="ok" value="提交" type="submit"/>
   </form>
  </body>
</html>

 

second.jsp

Html代码 <embed type="application/x-shockwave-flash" width="14" height="15" src="http://awp.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" flashvars="clipboard=%3C%25%40%20page%20language%3D%22java%22%20pageEncoding%3D%22UTF-8%22%25%3E%0A%3C!doctype%20html%20public%20%22-%2F%2FW3C%2F%2FDTD%20XHTML%201.0%20Transitional%2F%2FEN%22%20%0A%22http%3A%2F%2Fwww.w3.org%2FTR%2Fxhtml1%2FDTD%2Fxhtml1-transitional.dtd%22%3E%0A%3Chtml%3E%0A%20%20%3Chead%3E%0A%20%20%20%20%3Ctitle%3E%E6%88%91%E6%98%AF%E6%8F%90%E4%BA%A4%E7%AC%AC%E4%BA%8C%E4%B8%AAFORM%E7%9A%84%E9%A1%B5%E9%9D%A2%3C%2Ftitle%3E%0A%20%20%3C%2Fhead%3E%0A%20%20%3Cbody%3E%0A%20%20%20%3Cform%20action%3D%22%3C%25%3Drequest.getContextPath()%25%3E%2Fsecondpath.do%3Fmethod%3DsecondForm%22%20method%3D%22post%22%3E%0A%20%20%20%09%3Cinput%20name%3D%22name%22%20value%3D%22%22%20type%3D%22text%22%2F%3E%0A%20%20%20%09%3Cinput%20name%3D%22ok%22%20value%3D%22%E6%8F%90%E4%BA%A4%22%20type%3D%22submit%22%2F%3E%0A%20%20%20%3C%2Fform%3E%0A%20%20%3C%2Fbody%3E%0A%3C%2Fhtml%3E" quality="high" allowscriptaccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>
  1. < %@ page  language = "java"   pageEncoding = "UTF-8" % >   
  2. <!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN"   
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >   
  4. < html >   
  5.   < head >   
  6.     < title > 我是提交第二个FORM的页面 </ title >   
  7.   </ head >   
  8.   < body >   
  9.    < form   action = "<%=request.getContextPath()%>/secondpath.do?method=secondForm"   method = "post" >   
  10.     < input   name = "name"   value = ""   type = "text" />   
  11.     < input   name = "ok"   value = "提交"   type = "submit" />   
  12.    </ form >   
  13.   </ body >   
  14. </ html >   
<%@ page language="java" pageEncoding="UTF-8"%>
<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>我是提交第二个FORM的页面</title>
  </head>
  <body>
   <form action="<%=request.getContextPath()%>/secondpath.do?method=secondForm" method="post">
   	<input name="name" value="" type="text"/>
   	<input name="ok" value="提交" type="submit"/>
   </form>
  </body>
</html>

 

display.jsp

Html代码 <embed type="application/x-shockwave-flash" width="14" height="15" src="http://awp.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" flashvars="clipboard=%3C%25%40%20page%20language%3D%22java%22%20pageEncoding%3D%22UTF-8%22%25%3E%0A%3C!doctype%20html%20public%20%22-%2F%2FW3C%2F%2FDTD%20XHTML%201.0%20Transitional%2F%2FEN%22%20%0A%22http%3A%2F%2Fwww.w3.org%2FTR%2Fxhtml1%2FDTD%2Fxhtml1-transitional.dtd%22%3E%0A%3Chtml%3E%0A%20%20%3Chead%3E%0A%20%20%20%20%3Ctitle%3E%E6%98%BE%E7%A4%BA%E9%A1%B5%E9%9D%A2%3C%2Ftitle%3E%0A%20%20%3C%2Fhead%3E%0A%20%20%3Cbody%3E%0A%20%20%3Cbr%20%2F%3E%0A%20%20%20%E8%A1%A8%E5%8D%95%E6%8F%90%E4%BA%A4%E7%9A%84%E5%86%85%E5%AE%B9%E4%B8%BA%EF%BC%9A%24%7Bname%7D%20%3Cbr%20%2F%3E%3Cbr%20%2F%3E%0A%20%20%20%3Ca%20href%3D%22first.jsp%22%3E%E6%89%93%E5%BC%80%E8%A1%A8%E5%8D%951%3C%2Fa%3E%3Cbr%20%2F%3E%3Cbr%20%2F%3E%0A%20%20%20%3Ca%20href%3D%22second.jsp%22%3E%E6%89%93%E5%BC%80%E8%A1%A8%E5%8D%952%3C%2Fa%3E%0A%20%20%3C%2Fbody%3E%0A%3C%2Fhtml%3E%0A" quality="high" allowscriptaccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>
  1. < %@ page  language = "java"   pageEncoding = "UTF-8" % >   
  2. <!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN"   
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >   
  4. < html >   
  5.   < head >   
  6.     < title > 显示页面 </ title >   
  7.   </ head >   
  8.   < body >   
  9.   < br   />   
  10.    表单提交的内容为:${name} < br   /> < br   />   
  11.    < a   href = "first.jsp" > 打开表单1 </ a > < br   /> < br   />   
  12.    < a   href = "second.jsp" > 打开表单2 </ a >   
  13.   </ body >   
  14. </ html >   
<%@ page language="java" pageEncoding="UTF-8"%>
<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>显示页面</title>
  </head>
  <body>
  <br />
   表单提交的内容为:${name} <br /><br />
   <a href="first.jsp">打开表单1</a><br /><br />
   <a href="second.jsp">打开表单2</a>
  </body>
</html>

 

Action必须继承DispatchAction,感觉其实一个action还是只能对应一个form

这里的方法其实是利用action的path 多个path可以指向同一个action。

分享到:
评论

相关推荐

    DispatchAction实例

    在实际的Web应用程序开发中,通常一个URL对应一个Action,而`DispatchAction`则允许一个Action处理多个不同的请求,每个请求映射到Action中的不同方法,提高了代码的可维护性和组织性。 `DispatchAction`的核心机制...

    struts中dispatchAction用法

    DispatchAction是Struts提供的一个可扩展的Action类,它允许开发者将一个单一的Action类拆分成多个子方法,每个子方法处理特定的业务逻辑,从而提高了代码的组织性和可维护性。 DispatchAction的工作原理是通过...

    struts DispatchAction

    总之,Struts DispatchAction是Java Web开发中一种有效的请求分发机制,它允许在一个Action类中组织和管理多个业务处理方法,提高了代码的可读性和可维护性。然而,随着技术的发展,如Struts2的出现,开发者可以选择...

    DispatchAction、LookupDispatchAction、SwitchAction的应用

    其核心作用是允许将多个原本需要独立 Action 处理的任务合并到一个 Action 中进行处理,从而简化了 Action 的管理和维护工作。 **1.1 为什么要使用 DispatchAction** 在传统的 Struts 应用中,每一个业务逻辑操作...

    Struts中等同于DispatchAction类方法

    在早期的Struts版本中,`DispatchAction`类是一个核心组件,它允许我们通过单一的Action类处理多个请求,通过在请求URL中指定不同的方法名来调用不同的业务逻辑。 标题提到的"Struts中等同于DispatchAction类方法...

    EventDispatchAction类处理一个form多个submit

    `EventDispatchAction`是`DispatchAction`的一个子类,主要功能是简化处理多个提交按钮的情况。与`LookupDispatchAction`相比,它的使用更为便捷,无需与属性文件关联,也不需要手动在`getKeyMethodMap`方法中进行...

    J2EE_高级Action

    - `DispatchAction`降低了Action与视图之间的耦合度,因为它不需要为每一个请求创建一个新的Action类。 - 但是,这种方式也增加了Action自身的复杂度,因为一个Action类需要处理多种业务逻辑。 **示例代码**: ```...

    Action使用说明

    如果希望在保持每个请求路径对应一个`&lt;action&gt;`元素的同时,又能够在一个Action类中处理多个请求路径,可以选择继承`MappingDispatchAction`。 **配置示例**: ```xml &lt;action path="/mapping/login" type=...

    深入解析Java的Struts框架中的控制器DispatchAction

    DispatchAction是Struts提供的一个扩展Action类,它允许在一个Action类中实现多个业务处理方法,从而解决了创建大量Action类的问题。通常,一个Action类只有一个execute()方法,但通过DispatchAction,我们可以根据...

    LookUpDispachAction的用法详解

    通常,一个Action类对应一个或多个业务逻辑方法,每个方法处理特定的用户请求。然而,当一个Action需要处理多种操作时,LookUpDispatchAction就显得特别有用。它通过基于请求参数的值来决定执行哪个业务方法,而不是...

    Struts开发指南之工作流程.doc

    - **使用DispatchAction**:如果一个Action需要执行多种不同的操作,可以考虑使用DispatchAction来简化代码结构。 - **增强灵活性**:通过使用`DynaActionForm`支持更灵活的表单数据处理。 综上所述,Struts框架的...

    北大青鸟Y2(Struts)ppt

    DispatcherAction 允许我们将一个 Action 分解为多个更小的 Action 方法,每个方法处理特定的业务逻辑。这样做的好处是代码结构更清晰,可维护性更强。通过在 Action 配置中指定对应的 execute 方法,...

    菜鸟学struts1必备 API

    5. DispatchAction:Struts1提供的一种特殊Action,它将一个请求分发到多个子方法,提高代码可维护性。 二、主要组件详解 1. Controller:在Struts1中,Controller由StrutsServlet和ActionServlet实现,它们负责...

    Struts、Spring、Hibernate、SSH框架总结

    DispatchAction是Struts提供的一种扩展机制,它允许我们在一个Action类中定义多个处理不同请求的方法,提高了代码的组织性和复用性。通过DispatchAction,我们可以减少Action Bean的数量,提升系统的可维护性。使用...

    LookupDispatchAction 是使用方法

    默认情况下,Struts1的动作类只有一个`execute()`方法,但使用`LookupDispatchAction`时,可以定义多个处理特定请求的方法,每个方法对应一个特定的请求参数。 二、配置与使用 1. 配置struts-config.xml 首先,需要...

    Struts原理(二)

    DispatchAction是Struts提供的一种特殊类型的Action,用于解决一个Action中处理多个业务操作的问题。传统的Action通常只有一个execute方法,而DispatchAction则允许我们根据传入的参数值调用对应的方法。例如,在...

    struts高级日记

    `DispatchAction` 在 Struts 1.2 版本中引入,它可以将一个 Action 映射到多个处理方法上。这使得一个 URL 可以对应不同的处理逻辑,提高了代码的复用性和灵活性。 例如,在配置文件中指定一个参数(如 `status`)...

    struts精典实例开发教程(源代码)

    1. **Action**:Action是业务逻辑处理的中心,负责接收请求,处理数据,并返回一个表示结果的ActionForward对象。开发者通常会自定义Action类,实现特定的业务逻辑。 2. **Form Bean**:Form Bean用于在视图和控制...

    struts例子struts例子

    DispatchAction是Struts中一个非常实用的Action,它允许在一个表单中有多个提交按钮,每个按钮触发不同的处理逻辑。通过DispatchAction,开发者可以为不同的提交操作指定不同的处理方法,提高了代码的组织性和可复用...

Global site tag (gtag.js) - Google Analytics