• Post Reply Bookmark Topic Watch Topic
  • New Topic

session to pass values (page a to page b)  RSS feed

Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have a page_a.jsp. It is a listing of records. Each row has a link to go into details page, page B.
Look at it as like a sales listing. Each row has sales date, remarks, amount. And the sales date is made into Href, so that when i click it, it opens up page B.jsp which shows the actual sales details for that day.

When generating page_a.jsp, for each row's link, I generated random no. for the ID, ie. <a href='page_b?Id=2132324343567'>. I then create a session variable, it holds a delimited string, "~2132324343567-23~". The tilde is delimiter and the number after dash is the actual ID. With each new row, the random ID and its corresponding actual ID is appended to the string inside session. (Reason doing this is, I do not want user to know the primary key of that sales record, hence I used a meaningless Id, mapped to its actual Id via session, when user is at Page B, they see the query string [Id] value as some meaningless numbers).

To generate the string, this is what I do, in the very beginning, create the IndexTable session, and set it to empty string, Initializing it.

Iterate through the listing rows:
For Each Row : actual Id gotten from DB,

When a user clicks on a link to go to details page, page_b, the random Id gets passed over, and I retrieve it via request.getParameter("Id"). I then get the session attribute, perform some search to get the actual Id from its random Id. (substring and indexOf etc, slicing out the matched random Id and then getting its value after dash). Now I have the actual Id and i can do a SQL query successfully to show the sales details.

At the very end of page B, i set the session value back to only "~", without data anymore. This is so that, if the user refresh page B, it will no longer be valid. I also have in mind to response.redirect user back to Listing (page A) should they refresh.

Page B Coding:

Now the problem is: if i continuously click random links from the listing, go to details, come back to listing, clicks another row for testing purposes, ocassionally when I come to page B, the session variable holds only the value "~" when at the start of the page, which means I will not be able to get the actual ID because the reference indexing table is magically reset. By right, it should not happen, as I only reset it to tilde at the very last line of code in page B.

Anyone can help?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!