【发布时间】:2018-03-23 17:58:28
【问题描述】:
基本上就是标题所说的。我有一个应用程序可以让用户更新数据库上的信息。在代码中,我设置了响应以在成功时返回消息:
public Response updatePerson(@PathParam("id") int id, @FormParam("name") String name) throws Exception {
Profile profile = new Profile(id, name)
manager.updateProfile(id, person);
return Response.status(201).entity("Profile updated.").build();
不过,我也想做一个重定向,可以这样做:
public Response updatePerson(@PathParam("id") int id, @FormParam("name") String name) throws Exception {
Person person = new Person(id, name)
manager.updatePerson(id, person);
return Response.seeOther(new URI("/home")).build()
我的问题有两个:
为 POST 方法返回响应时,最佳做法是什么?是否应该有响应正文确认 POST 成功,或者代码是否足够?
有没有什么方法可以将这两个操作结合起来,从而返回响应正文上的实体,同时执行重定向?
【问题讨论】:
标签: java redirect post response httpresponse