简体   繁体   English

如何在JAX-RS中设置HTTP错误代码

[英]How to set an HTTP error code in JAX-RS

I have a web service using jar-rs. 我有一个使用jar-rs的Web服务。 How do I throw a custom http error code to the calling application? 如何向调用的应用程序抛出自定义的HTTP错误代码?

Thanks 谢谢

The Response class lets you create a response with a specific HTTP Status . 通过Response类,您可以创建具有特定HTTP Status的响应。 You can also extend WebApplicationException . 您还可以扩展WebApplicationException

There are a couple of examples in the JAX-RS 1.0 features overview docs , in the 'Building Responses' and 'WebApplicationException and mapping Exceptions to Responses' sections that will tell you all you need to know to get started. JAX-RS 1.0功能概述文档中有两个示例,在“构建响应”和“ WebApplicationException以及将异常映射到响应”部分中,它们将告诉您入门所需的全部知识。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM