[英]http response Header information
所以對於某些人(如果不是全部),這可能是一個愚蠢的問題,但是我有這個響應頭:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-Atr: 10
X-Atr2: 1
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Tue, 29 Mar 2016 09:17:26 GMT
以及隨之而來的結果:
{"site": [
{
"id": "1",
"name": "James"
},
{
"id": "2",
"name": "Katia"
},
{
"id": "3",
"name": "Sam"
}
我想要做的是更改HTTP / 1.1 200 ,以防萬一我得到了類似HTTP / 1.1 206的信息,您得到了一些結果 ,同時顯示了JSON結果。 並且如果我們沒有任何結果,它將是: HTTP / 1.1 400未找到任何結果 ,而JSON結果將是:
[]
所以我嘗試了以下內容:
if (response.getSite().size() <= 0) {
responseHttp.sendError(HttpServletResponse.SC_ACCEPTED, "you have some results");
} else {
responseHttp.sendError(HttpServletResponse.SC_ACCEPTED, "you have some results");}
在兩種情況下,它都編輯了HTTP / 1.1,但不顯示任何消息,也不顯示JSON結果。
希望我能很好地解釋我的問題,謝謝您的時間和幫助。
我認為您的意思是您想設置響應狀態,因此我建議使用類似以下內容的方法:
if (response.getSite().size() <= 0) {
responseHttp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Bad Request");
} else {
responseHttp.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
//your other codes for sending JSON response goes here:
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.