我有一个
JSP
页面,用户在其中填写表单。
servlet获取用户输入,进行一些计算,发送一些电子邮件,然后将用户重定向到另一个页面。
问题是“发送电子邮件”部分会持续几秒钟,所以用户从提交表单到显示新页面都要等待很长时间。
在servlet中,顺序是:
//...
//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
//...
尽管事实上
sendRedirect
首先,直到
sendEmail
方法已完成…
我可以用一个
ServletContextListener
在哪里运行,例如每10分钟,检查是否有电子邮件要发送。
但是,有没有一种方法可以向用户显示新页面,然后servlet继续发送电子邮件?