Jersey 可通过状态代码查看
JAX-RS 实现 Jersey 通过 Viewable 类支持 MVC 样式 Web 应用程序,该类是模板名称和模型对象的容器。它是这样使用的:
@GET
public Viewable get() {
return new Viewable("/index", "FOO");
}
我想知道如何用这种方法返回状态代码。上面的代码会隐式返回 200
,但这在任何情况下都是不合适的。有没有办法显式设置状态代码?
The JAX-RS implementation Jersey supports MVC style web applications through the Viewable
class, which is a container for a template name and a model object. It is used like this:
@GET
public Viewable get() {
return new Viewable("/index", "FOO");
}
I wonder how a status code could be returned with this approach. The above would implicitly return 200
, but that wouldn't be appropriate in any case. Is there a way to set a status code explicitly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须返回一个
Response
,其中设置了正确的状态代码和包含您的Viewable
的标头,例如:You will have to return a
Response
set up with the correct status code and headers containing yourViewable
, e.g.:嗯,您可以这样在球衣中创建自定义 Response 对象:
这将返回 200:
要返回不同的内容,请使用此方法:
希望有帮助......
Hmm you can create custom Response object in jersey thusly:
this will return a 200:
to return something different use this approach:
Hope that helped....