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




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

报告相同问题?

悬赏问题

  • ¥100 华为手机私有App后台保活
  • ¥15 sqlserver中加密的密码字段查询问题
  • ¥20 有谁能看看我coe文件到底哪儿有问题吗?
  • ¥20 我的这个coe文件到底哪儿出问题了
  • ¥15 matlab使用自定义函数时一直报错输入参数过多
  • ¥15 设计一个温度闭环控制系统
  • ¥100 rtmpose姿态评估
  • ¥15 java 通过反射找路径下的类,打包后就找不到
  • ¥15 通联支付网上收银统一下单接口
  • ¥15 angular有偿编写,