This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Redirect before long processing  RSS feed

 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a servlet that emails a report to the user when they fill in the form. Then the servlet redirects to another page. I try to send the redirect page first and let the process continue as shown in the code:

public void doGet(HttpServletRequest request, HttpServletResponse response) {
response.sendRedirect(response.encodeRedirectURL(�another_page�);
processAndsendEmail(); //takes 10 seconds
}

However the server (Tomcat) seems to send the redirect page after the doGet method is done. The user can not see the another_page until the process is finished.

Any idea to make this work?
Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to spin off the long process into a separate thread.

See the "Long Running Process" entry of Ben Souther's examples site.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!