繁体   English   中英

如何将用户重定向到页面,然后servlet执行方法

[英]How to redirect the user to a page and then the servlet executes a method

我有一个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继续发送电子邮件?

简单的答案:使用专用ThreadExecutor异步发送电子邮件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM