public class testAction extends Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
TestActionForm asd=(TestActionForm)form;
String username=asd.getUsername();
String password=asd.getPassword();
System.out.println(username);
System.out.println(password);
if ("123".equals(username)&&"123".equals(password))
{
request.setAttribute("username",username);
return mapping.findForward("LogSuccess");
}
else if request.setAttribute("password",password);
{
return mapping.findForward("LogFail");
}
else{
return mapping.findForward("Register");
}
}
}
request.setAttribute("username",username);
return mapping.findForward("LogSuccess");
}else if <<<<<<<你的条件那?很明确的这里有错!
request.setAttribute("password",password);
{
return mapping.findForward("LogFail");
}
else{
return mapping.findForward("Register");
}
你是想完成一个登陆:
if ("123".equals(username)&&"123".equals(password)){
request.setAttribute("username",username);
return mapping.findForward("LogSuccess");
}else if(!("123".equals(username)){//用户名错误
return mapping.findForward("Register");
}else{//密码错误
return mapping.findForward("LogFail");
}
{
request.setAttribute("username",username);
return mapping.findForward("LogSuccess");
}
可以return2次吗?
else if request.setAttribute("password",password);
这是对的吗?if表达式是怎么样的?能这样写吗?
你这里是啥意思,牛头不对马嘴,设置password的属性值可以作为if条件,而且也没加括号,就算加了括号也是错误的,你还在后面加了一个分号。
如果是正确的elseif语句,如回答者: lpchtsy 所写的。
想不明白你怎么判断的,这居然能用来判断。
而且注意,if后面一定要打上括号....