将响应标头添加到JAX-RS Webservice [英] Add Response Header to JAX-RS Webservice
问题描述
我正在尝试为我的一些webservice调用添加一些响应标头。我使用CXF 2.1.2和JAX-RS编写了我的Web服务。我需要返回一个对象,我还想在Response中添加一些标题。 如果不返回javax.ws.rs.core.Response对象,如何在响应中添加标头并仍然返回我的javabean?
I am trying add some response headers to some of my webservice calls. I wrote my webservice using CXF 2.1.2 and JAX-RS. I need to return an object and I also want to add some headers to the Response. Without returning a javax.ws.rs.core.Response object, how do I add a header to the response and still return my javabean?
推荐答案
您可以通过Web服务中的@Context注释注入对实际HttpServletResponse的引用,并使用addHeader()等添加标题。
You can inject a reference to the actual HttpServletResponse via the @Context annotation in your webservice and use addHeader() etc. to add your header.
这篇关于将响应标头添加到JAX-RS Webservice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!