我写了一个简单的登录注册,因为JS不咋地,就把“验证码”和“再次输入密码”放到了action层中处理,于是问题就来了。请看下我的action层的代码:
private String id;
private String pwd;
private String confirmPwd;
private String name;
private int sex;
private int question_id;
private String question;
private String answer;
private String email;
private String registrationDate;
private String securityCode;
private String inputSecurityCode;
然后是各种set和get方法 public String login() //我在struct.xml中配置了method,所以这里就不用execute()了
{
User user = null;
UserEbo userEbo = new UserEbo();
userEbo.setUserDao(new UserDAOImpl());
user = userEbo.login(id, pwd); //这里可以完美执行,id,pwd正确的话,可以成功获得user对象
ActionContext ctxt = ActionContext.getContext();
if(inputSecurityCode == securityCode) //重点在这,一直执行到这一步然后就不行了,问题是再调试过程中,这两个的值是一样的啊,天地良心,有图有真相,请看下面截图
{
if(user != null)
{
ctxt.put("user", user);
ctxt.put("label", "登录成功!自动跳转到主页并自动自动登录");
ctxt.put("hyperLink", "../index.jsp");
return "success";
}
else
{
return "fail";
}
}
else
{
return "fail"; //直接跳到这里,并结束
}
}欲哭无泪了。这是刚才的日志:
五月 11, 2013 9:38:51 上午 com.opensymphony.xwork2.util.logging.jdk.JdkLogger warn
WARNING: Parameter [id] is not on the excludeParams list of patterns and will be appended to action!
五月 11, 2013 9:38:51 上午 com.opensymphony.xwork2.util.logging.jdk.JdkLogger warn
WARNING: Parameter [inputSecurityCode] is not on the excludeParams list of patterns and will be appended to action!
五月 11, 2013 9:38:51 上午 com.opensymphony.xwork2.util.logging.jdk.JdkLogger warn
WARNING: Parameter [pwd] is not on the excludeParams list of patterns and will be appended to action!
五月 11, 2013 9:38:51 上午 com.opensymphony.xwork2.util.logging.jdk.JdkLogger warn
WARNING: Parameter [securityCode] is not on the excludeParams list of patterns and will be appended to action!然后是我的配置:
structs.xml
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" /> <package name="default" namespace="/" extends="struts-default">
<action name = "login" class = "user.action.UserAction" method = "login">
<result name = "success">../ok.jsp</result>
<result name = "fail">login.jsp</result>
</action>
<action name = "register" class = "user.action.UserAction" method = "register">
<result name = "success">../ok.jsp</result>
<result name = "fail">register.jsp</result>
</action>
</package>
</struts>我就想不通了,明明两个值一样,为什么还会这样呢?两个换成我都换成get方法也是如此,在Service层写了个方法再到action层调用也是如此求救啊
private String id;
private String pwd;
private String confirmPwd;
private String name;
private int sex;
private int question_id;
private String question;
private String answer;
private String email;
private String registrationDate;
private String securityCode;
private String inputSecurityCode;
然后是各种set和get方法 public String login() //我在struct.xml中配置了method,所以这里就不用execute()了
{
User user = null;
UserEbo userEbo = new UserEbo();
userEbo.setUserDao(new UserDAOImpl());
user = userEbo.login(id, pwd); //这里可以完美执行,id,pwd正确的话,可以成功获得user对象
ActionContext ctxt = ActionContext.getContext();
if(inputSecurityCode == securityCode) //重点在这,一直执行到这一步然后就不行了,问题是再调试过程中,这两个的值是一样的啊,天地良心,有图有真相,请看下面截图
{
if(user != null)
{
ctxt.put("user", user);
ctxt.put("label", "登录成功!自动跳转到主页并自动自动登录");
ctxt.put("hyperLink", "../index.jsp");
return "success";
}
else
{
return "fail";
}
}
else
{
return "fail"; //直接跳到这里,并结束
}
}欲哭无泪了。这是刚才的日志:
五月 11, 2013 9:38:51 上午 com.opensymphony.xwork2.util.logging.jdk.JdkLogger warn
WARNING: Parameter [id] is not on the excludeParams list of patterns and will be appended to action!
五月 11, 2013 9:38:51 上午 com.opensymphony.xwork2.util.logging.jdk.JdkLogger warn
WARNING: Parameter [inputSecurityCode] is not on the excludeParams list of patterns and will be appended to action!
五月 11, 2013 9:38:51 上午 com.opensymphony.xwork2.util.logging.jdk.JdkLogger warn
WARNING: Parameter [pwd] is not on the excludeParams list of patterns and will be appended to action!
五月 11, 2013 9:38:51 上午 com.opensymphony.xwork2.util.logging.jdk.JdkLogger warn
WARNING: Parameter [securityCode] is not on the excludeParams list of patterns and will be appended to action!然后是我的配置:
structs.xml
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" /> <package name="default" namespace="/" extends="struts-default">
<action name = "login" class = "user.action.UserAction" method = "login">
<result name = "success">../ok.jsp</result>
<result name = "fail">login.jsp</result>
</action>
<action name = "register" class = "user.action.UserAction" method = "register">
<result name = "success">../ok.jsp</result>
<result name = "fail">register.jsp</result>
</action>
</package>
</struts>我就想不通了,明明两个值一样,为什么还会这样呢?两个换成我都换成get方法也是如此,在Service层写了个方法再到action层调用也是如此求救啊
inputSecurityCode == securityCode)
字符串比较能用==么?
难道不是用equals么?
另外密码验证都是推荐在action层的,js验证的仅仅是格式而已。
这位高人,equals我可以尝试一下,就是你说的密码验证和验证码验证,我貌似也是在action层哈,我有什么不足之处请指出哈,我追求的是高质量编程哈,无限接近完美!!!
这位高人,equals我可以尝试一下,就是你说的密码验证和验证码验证,我貌似也是在action层哈,我有什么不足之处请指出哈,我追求的是高质量编程哈,无限接近完美!!!
JS验证格式的目的是降低服务器压力,把压力抛给客服端。
如果你的代码想更完美一点的话,我建议login()里面的那些东西封装起来,login()里面只留一个方法就够了。其他的封装到service层
这位高人,equals我可以尝试一下,就是你说的密码验证和验证码验证,我貌似也是在action层哈,我有什么不足之处请指出哈,我追求的是高质量编程哈,无限接近完美!!!
JS验证格式的目的是降低服务器压力,把压力抛给客服端。
如果你的代码想更完美一点的话,我建议login()里面的那些东西封装起来,login()里面只留一个方法就够了。其他的封装到service层哦哦,学习到了