web.xml lt;filter-mapping>我不想过滤html文件,怎么设置
1个回答
2016-12-23 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
关注
展开全部
不使用 /* 拦截所有,拦截想拦截的就可以了
类似下面的过滤方式
<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;
}
类似下面的过滤方式
<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;
}
Storm代理
2023-08-29 广告
2023-08-29 广告
"StormProxies是全球大数据IP资源服务商,其住宅代理网络由真实的家庭住宅IP组成,可为企业或个人提供满足各种场景的代理产品。点击免费测试(注册即送1G流量)StormProxies有哪些优势?1、IP+端口提取形式,不限带宽,I...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |