Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HTML->Servlet(mutiple request)

 
Angela D'souza
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have one html called main.html where I want to make two request at the same time to servlets. Can I make it???
Angela
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want, but you have to have a very good reason.
Firstly I have to ask why you need two requests and what it accomplishes. There are two ways to achieve what you want, but they're horrible hacks that are browser dependant and I'm not keen to mention them!
The first solution is to use an error in IE where a form can have a submit button that also executes a submit() method and causes the form to be submitted twice.
The second is to use Javascript and the JS Image object to make a call to load an image (passing all the params on the URL) to load the image in the background, similar to caching images when you're doing image roll-overs. All you care about is that the request is sent to the server.
If you ever quote me as saying you should implement either of these solutions, I'll come looking for you!
Depending on what your requirements are, there may be a third option which is preferable. This is the auto-submitting form. The client sends you the first request, and in the response you send a form with javascript at the end to submit the form. This takes care of request number two for you.
Hopefully this helps. I'm still interested in what is forcing you to send two requests from a single page though!
Dave
 
Gary McGath
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if this is related to what you have in mind, but I make use of a Java applet which calls a servlet to gather data. The applet opens an HttpURLConnection, then reads back the servlet's response by calling getInputStream(). If you do this, there are some tricky issues in Microsoft IE's implementation of URLConnection to watch out for. Also, if you want this servlet to handle cookies, you have to do some extra work.
 
David Hibbs
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to consider forwarding the request/response after the initial processing completes rather than sending another response. This would be a much more standard way of handling the situation where you need multiple things done after a single form is submitted.
i.e.
Form->Servlet 1->processing
->request dispatcher->forward
->Servlet 2->processing
->request dispatcher->forward
->Servlet 3
etc etc
This way you only need one request/response pair, you know the order, and you're not tied to any silliness or broken features of a particular browser.
 
Angela D'souza
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
Angela
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic