泽西岛(JSR311-实施)&重新导向 [英] Jersey (JSR311-Implementation) & Redirections
问题描述
是否可以在Jersey资源中重定向用户代理?
Is there a way to redirect the user-agent in a Jersey Resource?
在Spring MVC中,有一个"redirect:"语法,但是在Jersey的Viewable
类中没有可比的东西.我发现工作的唯一方法是使用HttpServletResponse.sendRedirect()
.
In Spring MVC there's the "redirect:"-syntax but I didn't find anything comparable in Jersey's Viewable
class. The only method I found working was using HttpServletResponse.sendRedirect()
.
推荐答案
您必须返回包含状态代码和Location
标头的Response
对象.最简单的方法是使用javax.ws.rs.core.Response.temporaryRedirect(URI)
.
You have to return a Response
object containing your status code and Location
-header. The easiest way is to use javax.ws.rs.core.Response.temporaryRedirect(URI)
.
使用Viewable
时,您可能需要抛出一个包含该Response
对象的WebApplicationException
.
When using Viewable
you might need to throw a WebApplicationException
containing that Response
object.
这篇关于泽西岛(JSR311-实施)&重新导向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!