• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

URL getting loaded twice

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is another problem ... firing a request with your browser won't cause the servlet to be invoked twice. On top of that, your browser does not call the JSP separately, that happens on the server.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pedro Nuno Santos wrote:Am I correct in thinking so?


No.

Either you are double clicking the button, or you have some code on the page that is causing the double submit.

Do you have script on the page doing form validation or other activities at form submit?
 
Pedro Nuno Santos
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

[doGet] Start #####################
[doGet] Request Query: action=action1&id=27
[doGet] Forward Address: /WEB-INF/jsp/view1.jsp
[doGet] End #####################
[doGet] Start #####################
[doGet] Request Query: action=action1&id=27
[doGet] Forward Address: /WEB-INF/jsp/view1.jsp
[doGet] End #####################



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...

Edit: @Bear Bibeault: No no javascript whatsoever, all content is pure HTML with some EL to access session varibles and do "foreach" cycles and "if" tests.
 
Pedro Nuno Santos
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
If you're gonna buy things, buy this thing and I get a fat kickback:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic