简体   繁体   中英

How to compare two products in two different pages

How to compare two products which are in different pages. ieI wil check one checkbox in one jsp page and other checkbox in another page.The problem is if i navigated to other page checkbox checked in first page is not working.Please help me using java and jsp.

When you say "checkbox checked in first page is not working", i assume you mean that the checkbox becomes unchecked. You need to store your data in session score for it to be available across JSP pages ( you could forward data from one page to another, but storing in session score is the simpler thing to do).

So when you move from one jsp to another, you could do something like

List productList = new ArrayList();
productList.add("xyzProdName");
session.setAttribute("ProductList", productList);

the attribute productList here represents a list which stores product names. You will have embbed such java code in your JSP. I suggest look up tag implementation instead of embedding code directly.

Once your product names are in session you can fetch their data and compare.

Make sure to empty the session if the user deselects products.

您将需要在内部保存该checkbox的状态,并在需要时进行比较。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM