jQuery in Action, 2nd edition*
The moose likes JSP and the fly likes Hi,How can i get the server time from jsp using the java script? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Hi,How can i get the server time from jsp using the java script?" Watch "Hi,How can i get the server time from jsp using the java script?" New topic
Author

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

Raveendra Ch
Greenhorn

Joined: Aug 09, 2009
Posts: 1
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

Joined: Jan 10, 2002
Posts: 60752
    
  65

"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.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Your browser serves the cached version of the page.
Try to override that last modified response header.


JDBCSupport - An easy to use, light-weight JDBC framework -
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hi,How can i get the server time from jsp using the java script?
 
Similar Threads
jsp file with java script error?
Not able to set attribute in JSP
calling jsp directl from HTML form
Retaining drop down values on page submit
Strange Behavior of JSP