簡體   English   中英

Jersey:將標頭添加到服務器響應中

[英]Jersey: adding headers to a server response

我正在使用Jersey,我有以下方法:

@POST
@Path("hello")
@Produces(MediaType.TEXT_HTML)
public String hello(@FormParam("username") String username)
{
    Gson gson = new Gson();
    CommunicationResponseM result = new CommunicationResponseM();

    String result = "hello";

    return gson.toJson(result);
}

到目前為止一切順利,但現在我需要添加一些標題。 我怎樣才能做到這一點?

謝謝!

PS:
我以這種方式啟動Jersey服務器:

    final HttpServer server = HttpServerFactory.create(baseUrl);
    server.start();

如果您正在尋找從http請求獲取標頭參數值的方法,那么您可以使用@HeaderParam注釋。 它類似於@FormParam注釋。

如果您希望在回復中添加標題,可以采用多種方法。

對於Jersey 1, Jersey 1.18用戶指南中有更多信息。 見2.5和2.13節。

有關Jersey 2用戶指南 ,請參閱第3章和第3.6節。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM