struts2中action实现ServletRequestAware 接口访问request时出现空指针异常:
java.lang.NullPointerException
解决:
问题出在我使用了自定义的拦截器,struts2.xml:
<action name="book_getAll" class="com.ld.struts2.action.BookAction" method="getAllBookInfo">
<interceptor-ref name="login_interceptors"></interceptor-ref>
<result name="getAll_success">/WEB-INF/jsp/login_success.jsp</result>
</action>
修改struts2.xml中action配置,添加<interceptor-ref name="servletConfig"></interceptor-ref>在自定义拦截器后:
<action name="book_getAll" class="com.ld.struts2.action.BookAction" method="getAllBookInfo">
<interceptor-ref name="login_interceptors"></interceptor-ref>
<interceptor-ref name="servletConfig"></interceptor-ref>
<result name="getAll_success">/WEB-INF/jsp/login_success.jsp</result>
</action>
通过此访问其他Servlet API时应该也要注意