2016-01-20 190 views
0

我正在運行使用tomcat的休息api服務器。 我試圖撥打電話:自定義錯誤頁面404

本地主機:8080/scriptalert%28XSS%29%2Fscript /用戶

和我得到這樣的響應:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> 
<html><head> 
<title>404 Not Found</title> 
</head><body> 
<h1>Not Found</h1> 
<p>The requested URL /�script�alert(�XSS�)�/script�/users was not found on this server.</p> 
</body></html> 

我想定製此消息,該URL不會在消息中。 我不確定誰在產生響應,是Apache嗎? tomcat的?球衣?

我已經嘗試添加錯誤映射到web.xml,但它沒有奏效。

回答

0

這是Tomcat生成的錯誤頁面。您可以禁用它,只需發送狀態代碼而不是錯誤頁面。要做到這一點,你需要通過只調用property(key, value)以下屬性設置爲true

ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR

Whenever response status is 4xx or 5xx it is possible to choose between sendError or setStatus on container specific Response implementation. E.g. on servlet container Jersey can call HttpServletResponse.setStatus(...) or HttpServletResponse.sendError(...) .

Calling sendError(...) method usually resets entity, response headers and provide error page for specified status code (e.g. servlet error-page configuration). However if you want to post-process response (e.g. by servlet filter) the only way to do it is calling setStatus(...) on container Response object.

If property value is true the method Response.setStatus(...) is used over default Response.sendError(...) .

Type of the property value is boolean . The default value is false .

您可以設置它在你的ResourceConfig子類的構造。或者如果您使用的是web.xml,只需將其設置爲init-param即可。在web.xml中,你將需要使用字符串版本

jersey.config.server.response.setStatusOverSendError