lyloverly 2010-08-25 13:53
浏览 314
已采纳

过滤器 ServletActionContext.setRequest(request) 抛异常

WEB.XML

authFilter
jp.cofesta.framework.web.filter.AuthorityFilter


encodingFilter
org.springframework.web.filter.CharacterEncodingFilter

encoding
UTF-8



struts2
org.apache.struts2.dispatcher.FilterDispatcher

<filter-mapping> 
  <filter-name>authFilter</filter-name> 
  <url-pattern>*.action</url-pattern> 
</filter-mapping> 

<filter-mapping> 
  <filter-name>encodingFilter</filter-name> 
  <url-pattern>*.*</url-pattern> 
</filter-mapping> 


<filter-mapping> 
  <filter-name>struts2</filter-name> 
  <url-pattern>*.action</url-pattern> 
</filter-mapping> 
<filter-mapping> 
  <filter-name>struts2</filter-name> 
  <url-pattern>*.jsp</url-pattern> 
</filter-mapping> 

过滤器 实现类

public class AuthorityFilter extends OncePerRequestFilter {

private String error = "/logout.action";

/**

  • error action setter method
  • @param error */ public void setError(String error) { this.error = error; }

/**

  • filter
  • @param request
  • @param response
  • @param filterChain */ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException, ServletException { String requestURI = request.getRequestURI(); //String shortRequestURI = requestURI.replace(request.getContextPath(),""); //ServletActionContext sac = new ServletActionContext(null,null); ServletActionContext.setRequest(request); User user = SecurityUtil.getLoginUser(); if (requestURI.endsWith(error)) { filterChain.doFilter(request, response); }else if (user == null && !requestURI.endsWith(Constants.LOGINACTION) && !requestURI.endsWith(Constants.WELCOMEACTION)) { String forwardPath = request.getContextPath() + error; (new HttpServletResponseWrapper(response)) .sendRedirect(forwardPath); } else { filterChain.doFilter(request, response); } } }

错误信息如下:

2010-8-25 13:34:56 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet default threw exception
java.lang.NullPointerException
at org.apache.struts2.ServletActionContext.setRequest(ServletActionContext.java:103)
at cc.yilian.invoicing.common.filter.AuthorityFilter.doFilterInternal(AuthorityFilter.java:51)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)

  • 写回答

1条回答 默认 最新

  • oyj7454103 2010-08-25 14:04
    关注

    jp.cofesta.framework.web.filter.AuthorityFilter 这个过来器的
    AuthorityFilter.java:51 行市哪行呢?!

    还有就是 其他的 struts2默认的过滤器 是否添加呢!














    dojo..*



    input,back,cancel,browse




    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥100 在连接内网VPN时,如何同时保持互联网连接
  • ¥15 MATLAB中使用parfor,矩阵Removal的有效索引在parfor循环中受限制
  • ¥20 Win 10 LTSC 1809版本如何无损提升到20H1版本
  • ¥50 win10 LTSC 虚拟键盘不弹出
  • ¥30 微信小程序请求失败,网页能正常带锁访问
  • ¥15 Matlab求解微分方程,如何用fish2d进行预优?