This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hello, I'm new to the whole servlet/jsp thing so bear with me (i.e. this maybe a noob question).
I'm currently writing a website that uses a servlet to catch all GETs and POSTs and forward the user to the appropriate jsp. These use EL & HTML to display the intended information. All my site links have the following format ?action=[actionName]¶m1=[param1]¶m2=[...]&... After catching the request I identify the action, execute it and forward the user to another .jsp (it can be the same one though) with: request.getRequestDispatcher(address).forward(request, response) where the address is the path to the jsp file (currently all of them are stored in \WEB-INF\jsp\ folder
Now my problem is that when I click an action link, the servlet catches 2 requests, one after the other, with the exact same URL... my guess is the browser, after making the first request, when loading the forwarded jsp, loads it with the same URL it made the request with in the first place. thus making the servlet execute again the same action... Am I correct in thinking so?
How can I prevent this from happening? Am I doing something wrong here?
I've been trying to debug this and it just got weirder... sometimes URLs are getting called twice other times not, but the process is always the same:
1) doGet catches link and calls executeAction()
2) executeAction searches the class annotations and corresponding methods and when it finds an annotation equal to the action it calls the method
3) method does it's stuff and returns the address to display (jsp file)
4) excecuteAction returns that address to doGet
5) doGet forwards with RequestDispatcher
I'm printing what the query string at doGet start and what the jsp path is just before the fowarding with the RequestDispatcher. Every single time both the query string and address are correct, only sometimes the doGet gets called twice, here is an example of a double call:
Above "Start" is printed just after doGet and "End" just after the RequestDispatcher is called. This happens when I click the link or when I copy-paste the address to the browser URL bar. However it is not persistant, i.e. does not happen everytime...
Pedro Nuno Santos
Joined: Aug 06, 2009
Well found something interesting today, I now have a way to replicate the double request (happens every time with firefox), however if I use IE8 and do the exact same sequence of actions the double request is never made. Now this may be some kink with my code the somehow doesn't expose it's ugly head with IE8.