Spring-MVC控制器重定向到“previous”页? [英] Spring-MVC controller redirect to "previous" page?

查看:131
本文介绍了Spring-MVC控制器重定向到“previous”页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个用于编辑Pony属性的表单,在我的Web应用程序中,有多个地方可以选择编辑Pony。例如,在小马列表中,每个小马旁边可能有一个编辑链接,当用户正在查看小马时,该视图中可能还有一个编辑链接。

Let's say I've got a form for editing the properties of a Pony, and in my web application there are multiple places where you can choose to edit a Pony. For instance, in a list of Ponies there might be an "edit" link next to each Pony, and when the user is viewing a Pony, there might also be an "edit" link in that view.

当用户在编辑Pony后点击提交时,我想将用户返回到他/她点击编辑链接时的页面。

When a user clicks "submit" after editing a Pony, I would like to return the user to the page that he or she was when clicking the "edit" link.

如何编写控制器以将用户重定向回到他们开始的位置?当然我可以通过将参数传递给控制器​​来做到这一点,但这似乎有点傻。我是否认为这一切都是错的,或者是我要做的事情呢?

How do I write my controller to redirect the user back to where they started? Certainly I can do this by passing a parameter to the controller, but that seems a little goofy. Am I thinking about this all wrong or is that pretty much what I'll have to do?

推荐答案

当然是一种选择,将在新窗口中打开编辑表单,因此所有用户必须关闭它并且它们回到它们所在的位置。

One option, of course, would be to open the edit form in a new window, so all the user has to do is close it and they're back where they were.

有一个在我当前的应用程序中,我需要做一些复杂的事情,然后将用户传递给表单,然后让它们返回到起点。在这些情况下,我将起始点存储在会话中,然后再将它们关闭。这对你正在做的事情来说可能有点过分。

There are a few places in my current application where I need to do something complicated, then pass the user to a form, and then have them return to the starting point. In those cases I store the starting point in the session before passing them off. That's probably overkill for what you're doing.

其他选项:1)你可以存储Referer标题并使用它,但这可能不可靠;并非所有浏览器都设置该标头。 2)在表单提交后,您可以在确认页面上使用javascript调用 history.go(-2)

Other options: 1) you can store the "Referer" header and use that, but that may not be dependable; not all browsers set that header. 2) you could have javascript on the confirmation page after the form submission that calls "history.go(-2)".

这篇关于Spring-MVC控制器重定向到“previous”页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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