java.lang.NullPointerException的问题

package com.zxcs.action;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.zxcs.interceptor.IsLoginedInterceptor;
import com.opensymphony.xwork2.ActionSupport;
import com.zxcs.bean.*;
import com.zxcs.service.UserService;

public class LoginAction extends ActionSupport{

/**
*
*/
private static final long serialVersionUID = 1L;
private User user;
private UserService service;

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}
public UserService getService() {
return service;
}

public void setService(UserService service) {
this.service = service;
}

public void validate() {
if(this.getUser().getUsername()==null||" ".equals(this.getUser().getUsername())){
this.addFieldError(this.getUser().getUsername(), "用户名不能为空!");
}
if(this.getUser().getUserpassword()==null||" ".equals(this.getUser().getUserpassword())){
this.addFieldError(this.getUser().getUsername(),"不能为空!");
}
}

@Override
public String execute() throws Exception
{
User user1 = null;
HttpServletRequest req=ServletActionContext.getRequest();
user1 = this.service.findLogin(this.getUser().getUsername(),this.getUser().getUserpassword());

if(user1!=null){

req.getSession(true).setAttribute(IsLoginedInterceptor.USER_SESSION_KEY, user1);//把用户信息保存到Session里,方便获取
return SUCCESS;

}else{
System.out.println("用户名和密码错误!");
this.addFieldError(this.getUser().getUsername(), "户名和密码错误!");
//ActionError("用户名和密码错误!");

return INPUT;

}

}
}

java.lang.NullPointerException
com.zxcs.action.LoginAction.validate(LoginAction.java:38)
com.opensymphony.xwork2.validator.ValidationInterceptor.doBeforeInvocation(ValidationInterceptor.java:249)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:261)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)

if(this.getUser().getUsername()==null||" ".equals(this.getUser().getUsername())){
this.addFieldError(this.getUser().getUsername(), "用户名不能为空!");
//你前面都判断出this.getUser().getUsername()==null,下面还执行this.getUser().getUsername()
//能不报空么
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-05-13
这个错误意思是 有些对象引用是空引用 没有指向一个具体的对象 自己检查一下追问

有可能是getuser()这个为空,那怎么改呢

第2个回答  2011-05-13
user1 = this.service.findLogin(this.getUser().getUsername(),this.getUser().getUserpassword());

if(user1!=null){
第3个回答  2011-05-13
LoginAction.java:38
第38行错误,你检查下,是不是没有获取到request对象。

相关了解……

你可能感兴趣的内容

大家正在搜

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