泽西岛(JSR311-实施)&重新导向 [英] Jersey (JSR311-Implementation) & Redirections

查看:110
本文介绍了泽西岛(JSR311-实施)&重新导向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆