Reputation: 542
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.
Upvotes: 2
Views: 423
Reputation: 10241
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.
Upvotes: 0
Reputation: 392
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"));
Upvotes: -1
Reputation: 38195
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).
Upvotes: 2