相当郁闷啊。addFieldError是将错误信息存储到ValidationAwareSupport validationAware中定义的 Map<String, List<String>> errors中。struts2的actin是prototype型的。每次访问的action都是新new 的实例。但是为社么我每次访问lginAction,查看<s:debug/>。fieldErrors是累加的,即存储了前一次的错误信息!!!!所以第二次访问开始,一直都被workflow拦截器拦截到错误,进不了action!!!! 为什么呢????{loginError=[登录密码错误!, 用户名错误!, 用户名错误!, 登录密码错误!, 登录密码错误!, 登录密码错误!, 登录密码错误!, 登录密码错误!]}
package com.fendou.authority.web.action;import java.util.Map;import org.apache.struts2.interceptor.SessionAware;import com.fendou.authority.webservice.GeneralException_Exception;
import com.fendou.authority.webservice.ISecurityHelper;
import com.fendou.authority.webservice.UserVO;
import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport implements SessionAware { /**
*
*/
private static final long serialVersionUID = 7787995295802692952L;
private String username;
private String password;
private UserVO visitor = null;
private ISecurityHelper securityHelper;
private Map<String,Object> session; public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public void setSecurityHelper(ISecurityHelper securityHelper) {
this.securityHelper = securityHelper;
} public void setSession(Map<String, Object> session) {
this.session = session;
} public String execute() throws Exception{
if(visitor!=null){
session.put("visitor", visitor);
}
return SUCCESS;
} @Override
public void validate() {
try {
visitor = securityHelper.queryUserByName(username, password);
} catch (GeneralException_Exception e) {
addFieldError("loginError",e.getMessage());
}
}
}
package com.fendou.authority.web.action;import java.util.Map;import org.apache.struts2.interceptor.SessionAware;import com.fendou.authority.webservice.GeneralException_Exception;
import com.fendou.authority.webservice.ISecurityHelper;
import com.fendou.authority.webservice.UserVO;
import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport implements SessionAware { /**
*
*/
private static final long serialVersionUID = 7787995295802692952L;
private String username;
private String password;
private UserVO visitor = null;
private ISecurityHelper securityHelper;
private Map<String,Object> session; public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public void setSecurityHelper(ISecurityHelper securityHelper) {
this.securityHelper = securityHelper;
} public void setSession(Map<String, Object> session) {
this.session = session;
} public String execute() throws Exception{
if(visitor!=null){
session.put("visitor", visitor);
}
return SUCCESS;
} @Override
public void validate() {
try {
visitor = securityHelper.queryUserByName(username, password);
} catch (GeneralException_Exception e) {
addFieldError("loginError",e.getMessage());
}
}
}
解决方案 »
- javascript小问题
- 求利用短信猫发短信的接口,写了一个好像不怎么对?
- Tomcat服务处于运行状态,修改JSP的内容,然后保存,eclipse的控制台抛出异常,重启Tomcat修改才能有效
- 关于JSP+servlet转换中文问题
- 那种生成方式更好,为什么?
- 谁有一个能用的可以支持打印,分页的报表工具啊··
- 菜鸟问题,EJB事物处理!!!
- 关于一个WEB。XML的配置问题,请高手帮忙回答
- 下载时出现的问题 getOutputStream() has already been called for this response
- 如何用XSL和XML的结合,来显示HTML文本输入框(Input)??期待中……
- linux tomcat 启动问题
- Spring视频下载(请求加精)
重写了validate方法; @Override
public void validate() {
System.out.println("before..." + this.hasErrors());
try {
visitor = securityHelper.queryUserByName(username, password);
} catch (GeneralException_Exception e) {
addFieldError("loginError",e.getMessage());
}
System.out.println("after..." + this.hasErrors());
}信息: Server startup in 58611 ms
before...false
[2010-04-03 10:32:16,573 ERROR] LogAspect - com.fendou.security.service.impl.SecurityHelper>>>登录密码错误!
[2010-04-03 10:32:16,573 ERROR] LogAspect - com.fendou.platform.exception.GeneralException: 登录密码错误!
2010-4-3 10:32:16 org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
信息: Application {http://impl.service.security.fendou.com/}SecurityHelperService#{http://api.service.security.fendou.com/}queryUserByName has thrown exception, unwinding now: com.fendou.platform.exception.GeneralException: 登录密码错误!
after...true
before...true
[2010-04-03 10:32:24,557 ERROR] LogAspect - com.fendou.security.service.impl.SecurityHelper>>>登录密码错误!
[2010-04-03 10:32:24,557 ERROR] LogAspect - com.fendou.platform.exception.GeneralException: 登录密码错误!
2010-4-3 10:32:24 org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
信息: Application {http://impl.service.security.fendou.com/}SecurityHelperService#{http://api.service.security.fendou.com/}queryUserByName has thrown exception, unwinding now: com.fendou.platform.exception.GeneralException: 登录密码错误!
after...true
before...true
[2010-04-03 10:32:41,571 ERROR] LogAspect - com.fendou.security.service.impl.SecurityHelper>>>用户名错误!
[2010-04-03 10:32:41,571 ERROR] LogAspect - com.fendou.platform.exception.GeneralException: 用户名错误!
2010-4-3 10:32:41 org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
信息: Application {http://impl.service.security.fendou.com/}SecurityHelperService#{http://api.service.security.fendou.com/}queryUserByName has thrown exception, unwinding now: com.fendou.platform.exception.GeneralException: 用户名错误!
after...true
后面就一直为true了
<bean id="loginAction" class="com.fendou.authority.web.action.LoginAction" scope="prototype">
<property name="securityHelper" ref="securityHelperService" />
</bean>