Hariprasath
Hariprasath

Reputation: 810

Get automatic response from Server

In my application i need to get any response to the jsp page automatically without any user action occur. How can i get that type of response like print some text to the jsp or invoke any function of the jquery from the server. Im using apache-tomcat7.0.42 and struts2 spring3 framework.

Upvotes: 0

Views: 201

Answers (2)

abcd
abcd

Reputation: 3210

You can use like below or you can use meta tag refresh

<%@ 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>

Upvotes: 0

Suresh Atta
Suresh Atta

Reputation: 121998

Seems you need meta tag refresh

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

Upvotes: 1

Related Questions