补充: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");
}
}
}
/*
* 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");
}
}
}
解决方案 »
- ibatis中传参问题
- 为什么用了DWR弹出提示Failed to read input 的对话框呢?
- 网上浏览报错net.jforum.exceptions.DatabaseStartupException: Error while trying to star
- web service 的调用
- 急,求Hibernate分页问题
- hibernate 表继承删除和查询问题
- Resin如何对单个appliction进行restart/stop/start操作?
- 请教Linux下的web service开发
- 请教:为什么我的用Weblogic中总是报这个错?该怎样处理?
- 哪里有<一步一步用jbuilder4开发ejb>下载或书买
- hibernate的小问题 在线等
- jbmp如何获得当前活跃的任务实例列表
先把validate设置成false
直接
<script>
function regist(){
window.location.href="regist.jsp"; //regist.jsp为你action跳转之后的页面
}
</script>
function regist(){
window.location.href="register.do";
}
</script>
表单的数据没有带过去
LoginForm 里的属性为null validate验证出错误