I have a JSP
page, where the user fills a form.
The servlet gets the user inputs, does some calculations, sends some emails and then redirects the user to another page.
The problem is that the "sending email" part lasts some seconds, so the user waits a lot from the moment he submits the form till the new page is shown.
In the servlet the order is :
//...
//servlet gets the user input and store all the info to an object `MyObject` filesToAttach
response.sendRedirect(destination); // show the new page to the user..
sendEmail(filesToAttach); //method that sends the emails
//...
Despite the fact that the sendRedirect
is first in order, the new page isn't shown to the user until the sendEmail
method is finished...
I could use a ServletContextListener
where it would run eg every 10 minutes and check if there emails to be sent..
However, is there a way to show the new page to the user and then the servlet continues to send the emails?
简单的答案:使用专用Thread
或Executor
异步发送电子邮件。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.