web.xml error-page 不起作用解決方案
今天遇到一個問題(應該是個老問題,但網上答案各異),記錄下來
在web.xml中配置錯誤頁面跳轉如下:
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/err/error.jsp</location>
</error-page>
或者
<error-page>
<error-code>500</error-code>
<location>/err/error.jsp</location>
</error-page>
製造空指標異常,啟動tomcat伺服器發現並不能跳轉到error.jsp,而是跳轉到IE的錯誤提示頁面
解決方案:
1.在IE【工具】->【Internet選項】->【高階】中勾掉【顯示友好http錯誤提示】;
2.確保error.jsp的大小>1024位元組。
這個從根本上沒有解決,只是找到了表面的問題。我們嘗試在apache配置裡配置或者nginx的配置裡配置錯誤頁面
nginx中的配置如下:
.建立自己的404.html頁面
2.更改nginx.conf在http定義區域加入:
fastcgi_intercept_errors on;
3.更改nginx.conf在server 區域加入:
error_page 404 = /404.html
4.測試nginx.conf正確性:
/opt/nginx/sbin/nginx –t
如果正確應該顯示如下資訊:
the configuration file /opt/nginx/conf/nginx.conf syntax is ok
configuration file /opt/nginx/conf/nginx.conf test is successful
5.重啟nginx
kill -HUP `cat /opt/nginx/nginx.pid `