This must be a common problem but for some reason I can't find a solution for it, even on these forums, maybe I'm just searching with the wrong words so my apologies in advance if this question has been covered before.
I have a JSP page where the user clicks a submit button which targets my servlet, once my servlet has finished running I want the user to go back to that very same jsp page and depending on an attribute set in the servlet(or something else if that's wrong) to display some sort of error or confirmation message. I've tried this both ways and in both cases it seems I'm very close but each way has a small problem I can't figure out. The first method I tried was with a RequestDispatcher as can be seen below.
This way everything works out and I can get the "AAA" attribute but unfortunately the URL still points to the servlet so if a user hits refresh then the servlet runs again. I then tried using a redirect while setting an attribute as many ways as I could think of which can be seen below with just one of the setAttribute methods.
This way I get the URL I want but unfortunately I can't get the "AAA" attribute. If anyone can shed some light on this for me and tell me what I'm doing/understanding wrong it would be greatly appreciated.
How are you accessing the attribute in your jsp for second scenario?
Joined: Feb 05, 2009
JSP for the first method which works
JSP for the second method which doesn't work
For the second method I've also tried getServletContext().setAttribute("AAA", "AAA"); in the servlet and then in the JSP I've tried pagecontext.getAttribute, session.getAttribute and request.getAttribute to get the attribute but can't in any case.