日期:2014-05-18  浏览次数:20757 次

ssh整合空指针问题
action

public class LoginAction extends ActionSupport {
   
private Account account;
private LoginService loginService;



public String execute() throws Exception{

Account user=loginService.find(account.getUsername(), account.getPassword());
if(user!=null){
return "success";
}else{
return "error";
}
}


public LoginService getLoginService() {
return loginService;
}

public void setLoginService(LoginService loginService) {
this.loginService = loginService;
}

public Account getAccount() {
return account;
}

public void setAccount(Account account) {
this.account = account;
}


}



struts.xml


 <package name="login" extends="struts-default">
      <action name="login" class="loginAction" >
         
         <result name="error">/fail.jsp</result>
         <result name="success">/success.jsp</result>
      </action>
    </package>


部分错误信息


HTTP Status 500 - 

--------------------------------------------

type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

java.lang.NullPointerException
com.test.action.LoginAction.execute(LoginAction.java:21)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:440)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:279)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:163)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:249)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
c