apache - 当url包含特殊字符时如何重定向错误页面?
问题描述
我有一个关于设置tomcat的问题。
我想在发生错误时显示常见错误页面。这是我的客户安全需求。
但是,如果我访问 www.mydomain.com/..%5c,我的常见错误页面将无法正常工作。
他们显示“HTTP ERROR 400 消息”。我想重定向我的常见错误页面..
这是我的 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 时如何重定向常见错误页面
解决方案
你可以试试这个程序。
我认为您可以在 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----");
}
}
我的英语很差
推荐阅读
- java - 将 Predicate<> 转换为子类型
- javascript - 如何在定义后立即使用变量 - js
- pdf-generation - Sejda HTML to PDF:如何在显示表格的所有页面上保留标题?
- python - 如何在 AllenNLP 中加载微调的 sciBERT 模型?
- .net-core - 我应该在管道中的 WebAppDeployment 之前还是之后进行 2e2 测试?
- vue.js - Vue 3 组件 - 试图调用 AJAX
- php - 教义迁移不会识别注释的更改(在生产中)
- c# - 在遍历循环时将新对象添加到字典中?
- spring - Spring Boot:找不到位于带有@Value注释的资源文件夹中的文件
- reactjs - 如何在同一行对齐 3 张卡片