问题描述
是否可以将 JAX-RS Web 服务重定向到另一个网页?
Is it possible to have a JAX-RS web service redirect to another web page?
就像使用 Servlet response.sendRedirect("http://test/test.html")
一样.
Like as you would do with Servlet response.sendRedirect("http://test/test.html")
.
JAX-RS Web 服务本身应该重定向.如果相关,我正在使用 RESTEasy.
The JAX-RS web service should itself redirect. I'm using RESTEasy if that's relevant.
推荐答案
是的,如果您的返回类型是 Response
(或 HttpServletResponse
)https://eclipse-ee4j.github.io/jersey.github.io/apidocs/1.19.1/jersey/javax/ws/rs/core/Response.html
Yes, you can do this in Jersey or any JAX-RS implementation (including RestEasy) if your return type is a Response
(or HttpServletResponse
)https://eclipse-ee4j.github.io/jersey.github.io/apidocs/1.19.1/jersey/javax/ws/rs/core/Response.html
您可以使用以下任一方法:
You can use either of the following:
Response.temporaryRedirect(URI)
Response.seeOther(URI)
临时重定向"返回 307 状态代码,而查看其他"返回 303.
"Temporary Redirect" returns a 307 status code while "See Other" returns 303.
这篇关于从 JAX-RS 服务发送重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!