JAVA if语句

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");
}
}

}

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");
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-09-21
if ("123".equals(username)&&"123".equals(password))

{
request.setAttribute("username",username);

return mapping.findForward("LogSuccess");
}
可以return2次吗?
else if request.setAttribute("password",password);
这是对的吗?if表达式是怎么样的?能这样写吗?
第2个回答  2009-09-21
else if request.setAttribute("password",password);
你这里是啥意思,牛头不对马嘴,设置password的属性值可以作为if条件,而且也没加括号,就算加了括号也是错误的,你还在后面加了一个分号。
如果是正确的elseif语句,如回答者: lpchtsy 所写的。
第3个回答  2009-09-21
else if request.setAttribute("password",password);
想不明白你怎么判断的,这居然能用来判断。
而且注意,if后面一定要打上括号....
第4个回答  2009-09-21
你啥问题啊?若是看代码是否错误,将代码放在Eclipse中,所有语法错误就都会标出

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网