JAVA if语句
来源:百度知道 编辑:UC知道 时间:2024/06/03 20:09:31
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");
}
}
}
@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");
}
}
}
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");
}
你是想完成一个登陆:
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");
}
if ("123".equals(username)&&"123".equals(password)){
request