File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Jsp, servlet back button issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Jsp, servlet back button issue" Watch "Jsp, servlet back button issue" New topic
Author

Jsp, servlet back button issue

farhan ahmed butt
Greenhorn

Joined: Aug 06, 2012
Posts: 12
Hey folks.. em really stuck into a problem so need help from you guys.. Actually I am creating a simple website in j2ee however I am not using beans since I want to keep it simple.. the structure of website is like I have different Jsp pages and every jsp page has a corresponding servlet which then connects the jsp page to database to store and retrieve data.. Now problem is that I have this one page index1 in which I select some option from drop down and then According to that option my next jsp page which is index2.jsp should load data from the database in its fields according to the option selected from index1.jsp... now index2 has a next and previous button.. I am storing the value of option selected from index1 to show on every jsp page just for now.. However when I click next on this index2.jsp it takes me to index3 with same option value but when I press previous button on index3 it takes me to the servlet of index2 which is Servlet2 in this case with the value of option being shown as NULL.. So it is kind of destroying the value from session when I press "previous" button. and after that all other pages show value of option as null as well. Another question is why I am having address of servlet instead of indexa when loading data into indexa from db using servlet.. Guys I really need help fast.. would really appreciate quick help..
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29237
    
139

Where are you storing the value in the session? Are you overwriting it? Are you passing it as a parameter in the URL?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
jatan bhavsar
Ranch Hand

Joined: Jul 23, 2008
Posts: 296

Hi Farhan,

Please Post some code here so we can help you better way.. if the values are stored in the session it must be avaiable.

Regards
Jatan
farhan ahmed butt
Greenhorn

Joined: Aug 06, 2012
Posts: 12
Okay I will post all the code here alongwith description...

Okay here is code for first index called.. indexnpro.jsp which upon getting the values forwards them to Servletnpro like this.. <form class="form-class" name="myform" action="Servletnpro" method="POST"> Note: remember since architecture here is MVC so every jsp will have its own servlet so values are not going direclty to another jsp but a servlet which then passes them to next jsp..... Now in Servletnpro's dopost method...

<--------------- this value I keep on losing when pressing back button.. It changes to null when it comes back again to this servlet..


/////////// From now is the simple code of database connectivity which will connect to database fetch the data based on user choice namely "corrtoepost" that I just stored in session.. and then will display it back on indexa.jsp ..



// here I am sending all the data fetched from db to the required jsp which will then dislpay the data.. Namely "indexa.jsp"


////////Now code Of Indexa.jsp

This page will show data fetched from Servletnpro discussed earlier..

Under body tag of page I retrieve that value of "corrtoepost" which I saved earlier in Servletnpro in a session.. I can see this value as of now..


and then display it on jsp page.. which is showing the right value as of now..

Now code for the next button in this page Remember next button is suppose to take me to next page with same correcttoepost value which I got from servlet.

Next

Now lets go to next page which is indexb.jsp

Here I again get the value of "corrtoe" from indexa.jsp like this..


Uptill Now I am getting the right value even on this page... Problem Arises once I press back button on this page....

Now code for back button on this page..

Now when I press this previous button I lose the toe value in indexa.jsp page and it shows corrtoe value on interface as null..... After this I tried to use Servlets Get method to get the value which would work once but after pressing next on indexa.jsp it would show null on indexb.jsp and rest of the pages... Problem is that why am I losing this value when I am storing it in session as well.!!! Kindly give me some idea about....

Another question is that when I press submit on indexnpro page why does it shows Servletnpro in address bar instead of indexa.jsp ... However it does shows the page indexa.jsp populated with values from indexa.jsp... I think this is the reason why I keep on losing the "corrtoe" value between jsp pages..
farhan ahmed butt
Greenhorn

Joined: Aug 06, 2012
Posts: 12
jatan bhavsar wrote:Hi Farhan,

Please Post some code here so we can help you better way.. if the values are stored in the session it must be avaiable.

Regards
Jatan

Hey bro just uploaded the code.. Kindly have a look and suggest me what to do...
farhan ahmed butt
Greenhorn

Joined: Aug 06, 2012
Posts: 12
Bear Bibeault wrote:Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information. Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.

thanks dude.. will do! :)
farhan ahmed butt
Greenhorn

Joined: Aug 06, 2012
Posts: 12
Bear Bibeault wrote:Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information. Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.


Hi bear,
Just edited the code.. Kindly have a look now..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jsp, servlet back button issue
 
Similar Threads
please observe this snippet
Permutations
create a faster index file for big number of value pairs
best approach to send data from a selected row of a table
Enumerating Letters (a=1,b=2..)