struts1 DispatchAcion

public class LoginAction extends DispatchAction {
	
	//注意不要再有execute()方法,否则自定义的方法会无效
	public ActionForward insert(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		LoginForm loginForm = (LoginForm)form;
		String username = loginForm.getUsername();
		String password = loginForm.getPassword();
		request.setAttribute("insertmsg", username+"---"+password);
		return mapping.findForward("insertpage");
	}
	
	
}

 配置如下:

<?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="loginForm" type="com.wang.forms.LoginForm"></form-bean>

  </form-beans>
  <global-exceptions />
  <global-forwards />
  <action-mappings >
  	<action path="/login" type="com.wang.action.LoginAction"
  		 scope="request" input="/index.jsp" name="loginForm"
  		 parameter="status"
  		 >
  		 <forward name="errorpage" path="/error.jsp"></forward>
  	
  		 <forward name="successpage" path="/success.jsp"></forward>
  		 <forward name="insertpage" path="/insert.jsp"></forward>
  	
  	</action>
  </action-mappings>
  <message-resources parameter="com.wang.action.ApplicationResources" />
</struts-config>

 jsp中代码片段,注意要用post提交,否则,将无法将status参数传过去

 <form action="login.do?status=insert" method="post" >
    <input type="text" name="username"><br>
    <input type="password" name="password" ><br>
    <input type="submit" value="login">
   </form>

 

你可能感兴趣的:(Dispatch)