• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hi,How can i get the server time from jsp using the java script?

 
Raveendra Ch
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,here is my code....

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="java.util.Calendar"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>My Sample Program</title>
<script>
function getTime(){
<%Calendar cal=Calendar.getInstance();%>
var minute=<%cal.get(Calendar.MINUTE);%>
var second=<%cal.get(Calendar.SECOND);%>
alert(minte+":"+second);
}
</script>

</head>
<body>
<form name="myForm" onsubmit="getTime()">
<h1 >Hi</h1>
<br>
<input type="submit" value="SUBMIT">


</form>

</body>
</html>

my problem is, suppose if i run this code at 9 am for the first time after deploying its giving the correct time(alert). Once the jsp is compiled
the next time on wards if i am running this code i am getting alert which gives me the time at which it has run previously. So what could be the mistake in this approach to get the server time from the javascript .
Thanks in advance,

CRB.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Raveendra Ch", please check your private messages for an important administrative matter.

Also, please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your browser serves the cached version of the page.
Try to override that last modified response header.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the point of mixing the JavaScript and (ick) Java code on the page? The Java code runs on the server and the JavaScript on the client.

You might benefit from reading this article in order to understand how JSPs work.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic