仅仅用了个struts1.2 做了个登录。 就出现空指针错误了。
很是悲催。一直找不到,很无辜啊!!
javax.servlet.ServletException: java.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 {这个是LOGINACTION 第十九行 用红色标记出来了。
@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");
}
}
}
public class LoginForm extends ActionForm {LoginForm。java
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;
}
}
<struts-config>struts-config.xml
<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>
<forward name="LoginFail" path="/loginfail.jsp"></forward>
</action>
</action-mappings>
<message-resources parameter="com.yourcompany.struts.ApplicationResources" />
</struts-config>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>