• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to display a page before finishing servlet stuff?

 
Vopli Vidoplyasova
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a user sign up form on my website. When info is submitted it goes to a servlet that puts it in a database and then is forwarded to a servlet that sends an email to the admin. Probably I should use JMS or something for this kind of thing, but for now I want to stick with the servlets and a couple of helper classes. I don't want the user to just stare at a blank screen while the info is processed (which should not take long, but anyway), how can I display a JSP of even a regular HTML page with some kind of "processing, please wait" message and then continue with the servlet stuff?

Thanks!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't.

If you want to do the processing in the background, fire off a thread to handle it asynchronously.
 
Vopli Vidoplyasova
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:You can't.

If you want to do the processing in the background, fire off a thread to handle it asynchronously.


Thanks Bear, I see. Is it ok to have all that thread stuff in the servlet or should I use a separate class for that?
 
Manish Singh
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see. Is it ok to have all that thread stuff in the servlet or should I use a separate class for that

what does it mean?

If you mean the code to persist that in the DB and sending the mail to the user you should move that to a separate class.
 
Vopli Vidoplyasova
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manish Singh wrote:If you mean the code to persist that in the DB and sending the mail to the user you should move that to a separate class.

No, that's not what I meant. What you're saying is clear. I was wondering about the very code that starts a new thread like

I've never seen a thread-related code in a servlet before, thus the question.
 
Manish Singh
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
# Thread mailer = new Thread(new MailerBean(userData));
# mailer.start();


what is the use of above code ? is it placed inside the service method and its there to send the mail to the user?
 
Vopli Vidoplyasova
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manish Singh wrote:
# Thread mailer = new Thread(new MailerBean(userData));
# mailer.start();


what is the use of above code ? is it placed inside the service method and its there to send the mail to the user?

Manish, you do not override the service() method. The code is from doPost() and what it does should be pretty clear - it creates a new instance of a class responsible for emails and passes it the data received from the user.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!