NullPointerException
在做对两个参数的查询时,有时会出现以下错误:
javax.servlet.ServletException: java.lang.NullPointerException
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
然后说代码是错在这:
public String execute() throws Exception { Map request = (Map) ActionContext.getContext().get("request"); if ( this.getUsername_c().equals("") || this.getCustomerid_c().equals("") ) { request.put("list", service.findAll()); } else { allRecorders = service.findUsersByUsernameCustomerid_count( this.getUsername_c() , this.getCustomerid_c() ) ; request.put("currentPage",new Integer(currentPage)) ; //当前页 request.put("allRecorders",new Integer(allRecorders)) ;//总记录总数 request.put("list", service.findUsersByUsernameCustomerid( this.getUsername_c() , this.getCustomerid_c() ,this.getCurrentPage(),lineSize)); } return SUCCESS; }if ( this.getUsername_c().equals("") || this.getCustomerid_c().equals("") )if(null != str && !"".equal(str)){}
[解决办法]
"".equals(this.getUsername_c()) || "".equals(this.getCustomerid_c())