永发信息网

web.xml lt;filter-mapping>我不想过滤html文件,怎么设置

答案:2  悬赏:50  手机版
解决时间 2021-03-19 18:46
  • 提问者网友:姑娘长的好罪过
  • 2021-03-19 05:59
web.xml lt;filter-mapping>我不想过滤html文件,怎么设置
最佳答案
  • 五星知识达人网友:话散在刀尖上
  • 2021-03-19 06:37
不使用 /* 拦截所有,拦截想拦截的就可以了

  类似下面的过滤方式
  
  encodingFilter
  org.springframework.web.filter.CharacterEncodingFilter
  
  encoding
  UTF-8
  

  

  
  encodingFilter
  *.action
  

  
  encodingFilter
  *.usl
  

  
  encodingFilter
  *.jsp
  

  
  encodingFilter
  *.view
  

  
  encodingFilter
  /jaxrs/*
  

  在filter类中判断一下,如果是.html结尾的就不过滤。
  HttpServletRequest req = (HttpServletRequest)request;
  //由于web.xml中设置Filter过滤全部请求,可以排除不需要过滤的url
  String reqURI = req.getRequestURI();
  if(reqURI.endsWith(".html")) chain.doFilter(request, response);
  HttpServletRequest req = (HttpServletRequest)request;
  //由于web.xml中设置Filter过滤全部请求,可以排除不需要过滤的url
  String reqURI = req.getRequestURI();
  if(reqURI.endsWith(".html")) chain.doFilter(request, response);

  chain是以下过滤方法中的chain吗?
  public void doFilter(ServletRequest request,
  ServletResponse response,
  FilterChain chain) throws IOException, ServletException{

  另外, if(reqURI.endsWith(".html")) 到底是 真还是假

  HttpServletRequest req = (HttpServletRequest)request;
  //由于web.xml中设置Filter过滤全部请求,可以排除不需要过滤的url
  String reqURI = req.getRequestURI();
  if(reqURI.endsWith(".html")) chain.doFilter(request, response);

  chain是以下过滤方法中的chain吗?
  public void doFilter(ServletRequest request,
  ServletResponse response,
  FilterChain chain) throws IOException, ServletException{

  另外, if(reqURI.endsWith(".html")) 到底是 真还是假

  就是这个chain,这个判断就是判断你放问的路径是否以.html结尾,你可以试试。

  HttpServletRequest req = (HttpServletRequest)request;
  //由于web.xml中设置Filter过滤全部请求,可以排除不需要过滤的url
  String reqURI = req.getRequestURI();
  if(reqURI.endsWith(".html")) chain.doFilter(request, response);

  chain是以下过滤方法中的chain吗?
  public void doFilter(ServletRequest request,
  ServletResponse response,
  FilterChain chain) throws IOException, ServletException{

  另外, if(reqURI.endsWith(".html")) 到底是 真还是假

  就是这个chain,这个判断就是判断你放问的路径是否以.html结尾,你可以试试。

  报错
  java.lang.IllegalStateException: getWriter() has already been called for this response
  public void doFilter(ServletRequest request, ServletResponse response,
  FilterChain chain) throws IOException, ServletException {
  //把ServletRequest和ServletResponse转换成真正的类型
  HttpServletRequest req = (HttpServletRequest)request;
  String reqURI = req.getRequestURI();
  if(reqURI.endsWith(".do")) chain.doFilter(request, response);
  System.out.println(reqURI);
  chain.doFilter(request, response);
  }

  我这里用过的原代码,没错,你看下你别的地方,用到response的地方
  //把ServletRequest转换成真正的类型
  HttpServletRequest req = (HttpServletRequest)request;
  String reqURI = req.getRequestURI();
  if(reqURI.endsWith(".html")) chain.doFilter(request, response);
  else{
  return;
  }
全部回答
  • 1楼网友:几近狂妄
  • 2021-03-19 07:58
不使用 /* 拦截所有,拦截想拦截的就可以了 类似下面的过滤方式 <filter> <filter-name>encodingfilter</filter-name> <filter-class>org.springframework.web.filter.characterencodingfilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingfilter</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping> <filter-mapping> <filter-name>encodingfilter</filter-name> <url-pattern>*.usl</url-pattern> </filter-mapping> <filter-mapping> <filter-name>encodingfilter</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping> <filter-mapping> <filter-name>encodingfilter</filter-name> <url-pattern>*.view</url-pattern> </filter-mapping> <filter-mapping> <filter-name>encodingfilter</filter-name> <url-pattern>/jaxrs/*</url-pattern> </filter-mapping> 在filter类中判断一下,如果是.html结尾的就不过滤。 httpservletrequest req = (httpservletrequest)request; //由于web.xml中设置filter过滤全部请求,可以排除不需要过滤的url string requri = req.getrequesturi(); if(requri.endswith(".html")) chain.dofilter(request, response); httpservletrequest req = (httpservletrequest)request; //由于web.xml中设置filter过滤全部请求,可以排除不需要过滤的url string requri = req.getrequesturi(); if(requri.endswith(".html")) chain.dofilter(request, response); chain是以下过滤方法中的chain吗? public void dofilter(servletrequest request, servletresponse response, filterchain chain) throws ioexception, servletexception{ 另外, if(requri.endswith(".html")) 到底是 真还是假 httpservletrequest req = (httpservletrequest)request; //由于web.xml中设置filter过滤全部请求,可以排除不需要过滤的url string requri = req.getrequesturi(); if(requri.endswith(".html")) chain.dofilter(request, response); chain是以下过滤方法中的chain吗? public void dofilter(servletrequest request, servletresponse response, filterchain chain) throws ioexception, servletexception{ 另外, if(requri.endswith(".html")) 到底是 真还是假 就是这个chain,这个判断就是判断你放问的路径是否以.html结尾,你可以试试。 httpservletrequest req = (httpservletrequest)request; //由于web.xml中设置filter过滤全部请求,可以排除不需要过滤的url string requri = req.getrequesturi(); if(requri.endswith(".html")) chain.dofilter(request, response); chain是以下过滤方法中的chain吗? public void dofilter(servletrequest request, servletresponse response, filterchain chain) throws ioexception, servletexception{ 另外, if(requri.endswith(".html")) 到底是 真还是假 就是这个chain,这个判断就是判断你放问的路径是否以.html结尾,你可以试试。 报错 java.lang.illegalstateexception: getwriter() has already been called for this response public void dofilter(servletrequest request, servletresponse response, filterchain chain) throws ioexception, servletexception { //把servletrequest和servletresponse转换成真正的类型 httpservletrequest req = (httpservletrequest)request; string requri = req.getrequesturi(); if(requri.endswith(".do")) chain.dofilter(request, response); system.out.println(requri); chain.dofilter(request, response); } 我这里用过的原代码,没错,你看下你别的地方,用到response的地方 //把servletrequest转换成真正的类型 httpservletrequest req = (httpservletrequest)request; string requri = req.getrequesturi(); if(requri.endswith(".html")) chain.dofilter(request, response); else{ return; } 这个是我刚才测试了的,只有html结尾的可以过。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯