i declare and assign an integer at the top of pageA (private int okay = 0
then depending on other stuff, if the information entered is right i assign it to 1 (okay = 1 and redirect them to pageB
if any thing goes wrong, okay is still 0 so i redirect them to the error page pageC
that all works but you see when they enter the right information (okay = 1) they are redirected to a pageB, but i need them to go back to the previous page pageA(dnt ask why, i just do).
but when i do that and enter wrong data it just goes to pageB and not the error page pageC
i think its because when they go back to pageA from pageB okay is 1 and not 0. i thought when you go back it just restarts the jsp page from scratch (where private int okay = 0; at the top). it only works when i restart the server (Tomcat).
Joined: Feb 11, 2005
the names robert johnson, im known as bobby but people call me bobby joe instead of bobby johnson, just coz its like my name. dont threaten me about banning me. if ure gona do, do it. id prefer u if u didnt but i really dont see any reason why ure so worked up over a name.
In your JSP you seem to have fallen into a common trap, and that is to create scripting variables as instance variables.
Remember that your JSP is converted into a servlet by the container. Since only one servlet is ever created and used for the JSP, the instance variables are creating a threading nightmare and do not get reset each time the page is hit.
My first suggestion is to remove all Java from your JSPs completely and use the JSTL, EL and custom actions for the dynamic portions of your pages.
If that's too big a step, at least remove the variables from scriptlet declarations (the <%! %> constructs). This is what is causing your variables to be declared as instance variables. [ March 21, 2005: Message edited by: Bear Bibeault ]
Joined: Feb 11, 2005
well pageA (the main page) is a servlet, pageB and pageC are jsp pages.
Originally posted by Robert Johnson: yea, but you see im about 60% into my project already and its due in three weeks, it just isnt possible to change them all. i have about 30 jsp pages and 15 servlets.
Then you are about 60% and three weeks from releasing an app with a severe threading problem. It's time to stop everything and get a real good grip on the Servlet/JSP lifecycle and how threading works in a Servlet environment.
Much easier at 60% then at 90% or after the product has been released.
is there any reason why you cannot declare "int okay=0" inside doGet() instead of making it a class data member? Since you thought it would be wiped out every time the jsp page or servlet reloaded, then doGet (or doPost, or service) are the perfect places for it. If you need it in functions called by doGet, pass it in as parameters or store it in the request (request.setAttribute("okay", new Integer(okay) .