• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to deal with loops on a servlet?

 
Michael Lars
Greenhorn
Posts: 20
Java jQuery Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have another question about servlets programming, How to deal with loops!

I have something similar in my code:



where param1, param2 is coming from browser but it work only first time and the browser keep loading when i click submit.

How can I submit all my parameters in this loop?

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A servlet must return a response, so it cannot just loop forever.

But if you are only talking about short loops to process a list of data, then a servlet is no different than any other class.
 
Michael Lars
Greenhorn
Posts: 20
Java jQuery Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:A servlet must return a response, so it cannot just loop forever.

But if you are only talking about short loops to process a list of data, then a servlet is no different than any other class.


Yes, there are short loops. But when I'm in the loop, the server didn't send me any response.
 
Paul Clapham
Sheriff
Posts: 21867
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, no, that won't usually happen until the loop ends and you return from the doGet or doPost method.

So as Bear already said, don't write an infinite loop. And don't try tricky stuff like trying to send part of the response at one time and then the rest later. There's too much buffering in the web to allow that to work successfully. Just take the request and send the response, that's all.
 
Joe Areeda
Ranch Hand
Posts: 332
2
Java Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael,

I'm just going to rephrase what Bear and Paul already said.

It sounds like you are not sending a (proper) response back to the browser.

This is done through the response.getOutputStream() stream and should be a valid HTML document.

If you are not in an infinite loop and the browser receives a response it should display it or at least stop waiting for it.

Joe
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!