从服务器获取自动响应

时间:2013-09-17 12:12:48

标签: java jquery jsp tomcat servlet-3.0

在我的应用程序中,我需要自动获得对jsp页面的任何响应,而不会发生任何用户操作。我怎样才能得到这种类型的响应,比如将一些文本打印到jsp或从服务器调用jquery的任何函数。我使用apache-tomcat7.0.42和struts2 spring3框架。

2 个答案:

答案 0 :(得分:1)

似乎你需要meta tag refresh

<meta http-equiv="refresh" content="10; url=urlToFetchData">

答案 1 :(得分:0)

您可以使用如下所示,也可以使用元标记刷新

<%@ page import="java.io.*,java.util.*" %>
<html>
<head>
<title>Auto Refresh Header Example</title>
</head>
<body>
<center>
<h2>Auto Refresh Header Example</h2>
<%
   // Set refresh, autoload time as 5 seconds
   response.setIntHeader("Refresh", 5);
   // Get current time
   Calendar calendar = new GregorianCalendar();
   String am_pm;
   int hour = calendar.get(Calendar.HOUR);
   int minute = calendar.get(Calendar.MINUTE);
   int second = calendar.get(Calendar.SECOND);
   if(calendar.get(Calendar.AM_PM) == 0)
      am_pm = "AM";
   else
      am_pm = "PM";
   String CT = hour+":"+ minute +":"+ second +" "+ am_pm;
   out.println("Crrent Time: " + CT + "\n");
%>
</center>
</body>
</html>