我有一个关于设置tomcat的问题。
我想在发生错误时显示常见错误页面。这是我的客户的安全需求。
但是,如果我访问www.mydomain.com/..%5c,我的常见错误页面无法工作。
它们显示"HTTP ERROR 400 message“。我想重定向我的常见错误页面..
这是我的web.xml配置。
<error-page>
<error-code>400</error-code>
<location>/error.html</location>
</error-page>
<error-page>
<error-code>401</error-code>
<location>/error.html</location>
</error-page>
<error-page>
<error-code>403</error-code>
<location>/error.html</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/error.html</location>
</error-page>
<error-page>
<error-code>405</error-code>
<location>/error.html</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/error.html</location>
</error-page>我添加了CATALINA_OPTS。-Dorg.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true
此选项适用于www.mydomain.com/%5c,但不适用于www.mydomain.com/..%5c
如何在访问www.mydomain.com/..%5c时重定向公共错误页面
发布于 2018-12-20 10:44:29
你可以试试这个程序。
我认为你可以在web.xml中配置你的过滤器。在过滤器中,您可以实现处理请求编码和特殊字符的逻辑,然后重定向到错误页面。
配置
<filter>
<filter-name>name</filter-name>
<filter-class>demoClass</filter-class>
</filter>
<filter-mapping>
<filter-name>name</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>要实现的类
public class demoClass implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
System.out.println("----init----");
}
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
//TODO code
}
@Override
public void destroy() {
System.out.println("----destory----");
}
}我英语不太好
https://stackoverflow.com/questions/53846836
复制相似问题