如何检查我是否从同一页面到达另一个页面

发布于 2024-12-22 17:57:00 字数 206 浏览 1 评论 0原文

我有一个 Java Web 应用程序。其中一页包含一个带有 3 个复选框和一个表格的表单。 根据选中的复选框,表中会填充不同的信息。 没有提交按钮。每当用户选中或取消选中其中一个框时,就会提交该表单。

理论上,我希望用户能够取消选中所有复选框,这将导致表为空。但是,如果用户从另一个页面到达该页面,或者在首次访问应用程序时,我希望他们默认选中其中一个复选框,并在表中显示相应的数据。

I have a Java Web App. One of the pages contains a form with 3 checkboxes and a table.
Depending on which checkboxes are checked, different info gets populated in the table.
There is no submit button. The form is submitted whenever the user checks or unchecks one of the boxes.

Theoretically, I want the user to be able to uncheck all the boxes, which will result in the table being empty. However, if the user arrives at the page from another page, or upon initial visit to the app, I want them to have one of the boxes checked by default, and the respective data displayed in the table.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

阳光的暖冬 2024-12-29 17:57:00

您可以通过 HTTP 方法区分对同一页面的请求(提交)和来自其他页面的请求(或直接 url 访问)。

让您的表单使用 POST 方法,并检查请求方法是否为 GET(直接访问或从其他页面链接)或 POST(表单提交)。

You could differentiate the request to the same page (submission) from the requests comming from other pages (or direct url access) by the HTTP method.

Make your form use a POST method and check if the request method is GET (direct access or link from another page) or POST (form submission).

梦回梦里 2024-12-29 17:57:00

最好根据 3 个复选框将 3 个不同的请求参数传递给 JSP/Servlet,并根据参数相应地修改表。

如果用户来自其他页面,请在 doGet 或 doPost 开始时将请求参数设置为默认值。

Better pass 3 different request parameters based on your 3 checkboxes to your JSP/Servlet and depending on the parameters modify the table accordingly.

if user is coming from another page, at the start of the doGet or doPost, set your request parameter to a default value.

征﹌骨岁月お 2024-12-29 17:57:00

您可以使用会话来帮助确定用户来自哪里。在页面重定向到另一个页面之前,让原始页面设置一些会话属性。在页面顶部的某个位置,您可以检查用户的会话属性以查看它们来自哪里,

第 1 页

session.putValue("referringPage", "Page1");

第 2 页

if (session.getValue("referringPage") != "Page2") {  
         //do something
}

编辑:

更好的方法可能只是使用类似

request.getHeader("Referer")); 的内容来检查标头

you can use sessions to help determine where you a user is coming from. Before a page redirects to another page have the orignal page set some session attribute. Somewhere at the top of the page you can check the user's session attribute to see where they are coming from

i.e.

Page 1

session.putValue("referringPage", "Page1");

Page 2

if (session.getValue("referringPage") != "Page2") {  
         //do something
}

Edit:

Better method might just be to check the header using something like

request.getHeader("Referer"));

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文