日期:2014-05-19  浏览次数:20712 次

struts1 空指针错误,比较简单! 有代码!
   仅仅用了个struts1.2 做了个登录。  就出现空指针错误了。
   很是悲催。一直找不到,很无辜啊!!
javax.servlet.ServletExceptionjava.lang.NullPointerException
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:535)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:433)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause 

java.lang.NullPointerException
com.yourcompany.login.LoginAction.execute(LoginAction.java:19)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


public class LoginAction extends Action {

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

LoginForm loginForm=(LoginForm)form;
if(loginForm.getLoginname().equals("qwe")){

return mapping.findForward("LoginSuccess");

}else{

return mapping.findForward("LoginFail");
}
}

}
  这个是LOGINACTION 第十九行 用红色标记出来了。

public class LoginForm extends ActionForm {
private String loginname=null;
private String password=null;
public String getLoginname() {
return loginname;
}
public void setLoginname(String loginname) {
this.loginname = loginname;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}

}
 LoginForm。java


<struts-config>
  <data-sources />
  <form-beans>
   <form-bean name="loginForm" type="com.yourcompany.login.LoginForm"></form-bean>
  </form-beans>
  
  <global-exceptions />
  <global-forwards />
  <action-mappings >
   <action 
   path="/login" type="com.yourcompany.login.LoginAction" name="loginForm">
   <forward name="LoginSuccess" path="/loginsuccess.jsp"></forward>
 &nb