Tomcat错误页面不生效
- 配置
<error-page>
<error-code>400</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>500</error-code>
<location>/error.html</location>
</error-page>
2.页面位置
斜杠/代表错误页面需要放置于tomcat的webapps路径下或者webapps的ROOT路径下,此时一般就能解决问题。如果仍然未解决,则往下看,或者检查当前tomcat的错误页面能否正常访问。
3.如果配置了nginx,则需要设置nginx错误页面
在nginx.conf中的server下配置,并在Tomcat的webapps的test目录下加上error.html错误页面,当出现400报错后,页面就会重定向到错误页面
server{
#监听443端口
listen 443;
#对应的域名
server_name localhost;
proxy_intercept_errors on;
error_page 400 https://localhost:8080/test/error.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/nginx/html;
}
location / {
root /usr/local/nginx/html;
#主页文件
index index.html;
}
}