补充:LoginForm
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.yourcompany.struts.form;import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;/** 
 * MyEclipse Struts
 * Creation date: 11-13-2008
 * 
 * XDoclet definition:
 * @struts.form name="loginForm"
 */
public class LoginForm extends ActionForm {
/*
 * Generated fields
 */ /** password property */
private String password; /** username property */
private String username; /*
 * Generated Methods
 */ /** 
 * Method validate
 * @param mapping
 * @param request
 * @return ActionErrors
 */
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
ActionErrors errors = new ActionErrors();
if("".equals(this.username)||this.username==null)
{
errors.add("username", new ActionMessage("Name.Null"));
}
if("".equals(this.password)||this.password==null)
{
errors.add("password",new ActionMessage("Password.Null"));
}
return errors;
} /** 
 * Method reset
 * @param mapping
 * @param request
 */
public void reset(ActionMapping mapping, HttpServletRequest request) {
// TODO Auto-generated method stub
} /** 
 * Returns the password.
 * @return String
 */
public String getPassword() {
return password;
} /** 
 * Set the password.
 * @param password The password to set
 */
public void setPassword(String password) {
this.password = password;
} /** 
 * Returns the username.
 * @return String
 */
public String getUsername() {
return username;
} /** 
 * Set the username.
 * @param username The username to set
 */
public void setUsername(String username) {
this.username = username;
}
}
这是:LoginAction  和registerAction代码一样/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.yourcompany.struts.action;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.yourcompany.struts.form.LoginForm;/** 
 * MyEclipse Struts
 * Creation date: 11-13-2008
 * 
 * XDoclet definition:
 * @struts.action path="/login" name="loginForm" input="/form/login.jsp" scope="request" validate="true"
 */
public class LoginAction extends Action {
/*
 * Generated Methods
 */ /** 
 * Method execute
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 */
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method stub
        String username =loginForm.getUsername();
        String password =loginForm.getPassword();
       if("zhu".equals(username)&&"zhu".equals(password))
        {
         return mapping.findForward("succ");
        }
        else{
         return mapping.findForward("fail");
        }
}
}

解决方案 »

  1.   

    validate验证有错误 
    先把validate设置成false
      

  2.   

    晕,干嘛非得跳转到action?
    直接
     <script> 
            function regist(){ 
              window.location.href="regist.jsp";  //regist.jsp为你action跳转之后的页面
              }  
        </script> 
      

  3.   

        <script> 
            function regist(){ 
              window.location.href="register.do"; 
              }  
        </script> 
    表单的数据没有带过去
    LoginForm 里的属性为null  validate验证出错误
      

  4.   

      恩,我就是不想再写一个regist.jsp页面
     
      

  5.   

    那我怎么把form也传给注册的action啊?