Java搜寻引荐来源 [英] Java seeking referer

查看:79
本文介绍了Java搜寻引荐来源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Struts和Java.问题是我的页面上有一些结果.用户可以单击一个项目并进行编辑.我希望在编辑用户后能够返回到结果.返回没有中断,但是如果他提交更新表格,他将不得不单击两次,我认为这可能有问题.

I am using Struts and Java. The problem is that I have a page with some results. The user can click an item and edit it. I want after editing the user to be able to return back to the results. Back isn't broken but if he submits the form for update he would have to click back 2 times I think and may have problem.

我已经尝试过header("Referer"),但这在Internet Explorer中不起作用.

I have tried header("Referer") but this doesn't work in Internet Explorer.

我正在尝试实施解决方案.有任何想法吗?我的想法是保存URL并在该URL的ID周围移动.当我想返回时,请从ID获取网址.将其存储在会话中不是解决方案,因为用户可能已经打开了多个窗口.

I am trying to implement a solution. Any ideas? My idea is to save url and move around an ID of that url. And when I want to return back get the url from ID. Storing it in the session is not a solution because the user may have opened multiple windows.

推荐答案

最好的方法是将其作为 request 参数传递.在编辑链接或按钮上,只需将当前URL传递为请求参数即可.这是一个带有链接的示例:

The best way is to pass it around as a request parameter. On the edit link or button, just pass the current URL along as request parameter. Here's an example with a link:

<a href="/login?from=${pageContext.request.requestURI}">edit</a>

或者(如果它是提交表单的按钮),而是以相同的形式将其作为隐藏的输入值传递:

Or if it's a button to submit a form, then rather pass it as hidden input value in the same form:

<input type="hidden" name="from" value="${pageContext.request.requestURI}">

在具有编辑表单的页面中,将其作为表单的隐藏输入值传输到后续请求:

In the page with the edit form, transfer it to the subsequent request as hidden input value of the form:

<input type="hidden" name="from" value="${param.from}">

在操作方法中,只需在完成操作后重定向到该URL.由于我不使用Struts,因此无法提供详细的Struts示例,但是下面是使用普通香草" Servlet的方法,因此您必须能够将其移植到Struts方法中:

In the action method, just redirect to that URL after finishing the action. Since I don't do Struts, I can't give a detailed Struts example, but here is how you would do it with "plain vanilla" Servlet, you must be able to port it to a Struts approach:

response.sendRedirect(request.getParameter("from"));

这篇关于Java搜寻引荐来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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