简体   繁体   English

java:服务器(glassfish / tomcat)可以自动调用jsp吗?

[英]java: can a server(glassfish/tomcat) call a jsp automatically?

After deployment of a java project in spring hibernate can i call a jsp automatically after some interval without sending any request to the server? 在春季休眠Java项目后,我可以在一定间隔后自动调用jsp而不向服务器发送任何请求吗?

Can We use .bat file or .exe ? 我们可以使用.bat文件还是.exe文件?

Any suggestion 任何建议

Thanks 谢谢

使用过滤器监视请求,然后调用jsp

You should spawn a Thread and let it do the email retrieval and dumping emails to DB. 您应该产生一个线程,并让它执行电子邮件检索并将电子邮件转储到数据库。 You could start this Thread on application deployment using a ServletContextListener implementation registered in your web.xml. 您可以使用在web.xml中注册的ServletContextListener实现在应用程序部署时启动此线程。 Following articles might help you to get a more detail understanding. 以下文章可能有助于您更详细地了解。

http://docs.oracle.com/javase/tutorial/essential/concurrency/runthread.html http://docs.oracle.com/javase/tutorial/essential/concurrency/runthread.html

http://www.mkyong.com/servlet/what-is-listener-servletcontextlistener-example/ http://www.mkyong.com/servlet/what-is-listener-servletcontextlistener-example/

As I know a server can not call JSP automatically (can only to perform auto compilation). 据我所知,服务器无法自动调用JSP(只能执行自动编译)。 It task is out of nature of server. 它的任务超出了服务器的性质。 Application server cloud execute jsp pages only by requests. 应用服务器云仅通过请求执行jsp页面。 You can develop a tool (in java as example) which could simulate a request to the server by requesting some jsp page or execute a .class file of jsp page directly. 您可以开发一个工具(以Java为例),该工具可以通过请求一些jsp页面或直接执行jsp页面的.class文件来模拟对服务器的请求。 As another solution is to send http request to the server by telnet from command line which you can put into a .bat file and execute it after deployment. 另一种解决方案是通过telnet从命令行将http请求发送到服务器,您可以将其放入.bat文件并在部署后执行。 Also you can use http://curl.haxx.se/ tool to perform any type requests from command line to your server. 您也可以使用http://curl.haxx.se/工具执行从命令行到服务器的任何类型请求。

telnet example: telnet示例:

telnet 127.0.0.1 8080 telnet 127.0.0.1 8080

then 然后

GET /myapp/index.jsp GET /myapp/index.jsp

If you want to use the request to trigger server side behaviour, you should really consider to use an EJB-Timer as an alternative. 如果要使用请求来触发服务器端行为,则应该考虑使用EJB-Timer作为替代方案。

The other option is to use your infrastructure (cron, windows scheduler) to make a request. 另一个选择是使用您的基础结构(cron,Windows Scheduler)发出请求。

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

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