action处理多个事务

处理多个业务 时候要使用dispatchAction如图所示

photo

另外在parameter里面设置参数名称method

共以后Action里面使用。

/*

* Generated by MyEclipse Struts

* Template path: templates/java/JavaClass.vtl

*/

package com.jinchun.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.jinchun.form.RegisterForm;

/**

* MyEclipse Struts

* Creation date: 09-03-2008

*

* XDoclet definition:

* @struts.action path="/register" name="registerForm" input="/register.jsp" parameter="method" scope="request" validate="true"

*/

public class RegisterAction extends DispatchAction {

public ActionForward addUser(ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response) {

RegisterForm registerForm = (RegisterForm) form;

System.out.print("adduser");

return null;

}

public ActionForward updateUser(ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response) {

RegisterForm registerForm = (RegisterForm) form;

System.out.print("updateuser");

return null;

}

}

复制Exeute方法,生成业务Action同事去掉Exeute.不去的话form会默认找到他。

form表单里面修改如下

<html:form action="/register">

uname : <html:text property="uname"/><html:errors property="uname"/><br/>

upass : <html:text property="upass"/><html:errors property="upass"/><br/>

<html:submit onclick="forms[0].action='register.do?method=addUser'"/><html:cancel/>

</html:form>

<html:form action="/register">

uname : <html:text property="uname"/><html:errors property="uname"/><br/>

upass : <html:text property="upass"/><html:errors property="upass"/><br/>

<html:submit onclick="forms[1].action='register.do?method=updateUser'"/><html:cancel/>

</html:form>

顺便贴个美女养眼

美女

你可能感兴趣的:(apache,html,struts,MyEclipse,servlet)