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;public class LoginAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception{
LoginForm loginForm = (LoginForm)form;
if(loginForm.getUsername().equals("test")){ //此行有什么错误
return mapping.findForward("loginSuccess");
}else {
return mapping.findForward("loginFailure");
}
}}
我用struts1.3.10做登陆验证是出现 NullPointerException 错误,上面标记的行,其它地方检查了几次应该没问题
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;public class LoginAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception{
LoginForm loginForm = (LoginForm)form;
if(loginForm.getUsername().equals("test")){ //此行有什么错误
return mapping.findForward("loginSuccess");
}else {
return mapping.findForward("loginFailure");
}
}}
我用struts1.3.10做登陆验证是出现 NullPointerException 错误,上面标记的行,其它地方检查了几次应该没问题
可以使用
("fail").equals(str);
这样写,即使str为空,只会返回false,而不是空指针