jsp - auto refresh
TRANSCRIPT
Web This Site
Basic JSP Tutorials
JSP - Home
JSP - Overview
JSP - EnvironmentJSP - Architecture
JSP - Life Cycle
JSP - Syntax
JSP - Directives
JSP - ActionsJSP - Implicit Objects
JSP - Client Request
JSP - Server Response
JSP - Http Codes
JSP - Form ProcessingJSP - Writing Filters
JSP - Cookies Handling
JSP - Session Tracking
JSP - File Uploading
JSP - Handling DateJSP - Page Redirect
JSP - Hits Counter
JSP - Auto Refresh
JSP - Sending Email
Advanced JSP Tutorials
JSP - Standard Tag Library
JSP - Database Access
JSP - XML Data
JSP - Java Beans
JSP - Custom TagsJSP - Expression Language
JSP - Exception Handling
JSP - Debugging
JSP - Security
JSP - Internationalization
JSP Useful References
JSP - Quick Guide
JSP Useful Resources
JSP Useful Resources
Selected Reading
Computer Glossary
Who is Who
© 2012 TutorialsPoint.COM
Home References Discussion Forums About TP
JSP - Auto Refresh
Advertisements
Consider a webpage which is displaying live game score or stock market status or currencyexchange ration. For all such type of pages, you would need to refresh your web page regularlyusing referesh or reload button with your browser.
JSP makes this job easy by providing you a mechanism where you can make a webpage in such away that it would refresh automatically after a given interval.
The simplest way of refreshing a web page is using method setIntHeader() of response object.Following is the signature of this method:
public void setIntHeader(String header, int headerValue)
This method sends back header "Refresh" to the browser along with an integer value whichindicates time interval in seconds.
Auto Page Refresh Example:Following example would use setIntHeader() method to set Refresh header to simulate a digitalclock:
<%@ 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>
Now put the above code in main.jsp and try to access it. This would display current system timeafter every 5 seconds as follows. Just run the JSP and wait to see the result:
Auto Refresh Header ExampleCurrent Time is: 9:44:50 PM
To become more comfortable with other methods you can try few more above listed methods inthe same fashion.
Advertisements
JSP - Auto Refresh http://www.tutorialspoint.com/jsp/jsp_auto_refresh.htm
1 of 2 12/27/2012 10:11 PM
Vulnerability Specialistsecunia.com
Audit source code and analyse vulnerabilities.Your next job?
JSP - Auto Refresh http://www.tutorialspoint.com/jsp/jsp_auto_refresh.htm
2 of 2 12/27/2012 10:11 PM