File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Not SetInterval() is applicable for scriplet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Not SetInterval() is applicable for scriplet" Watch "Not SetInterval() is applicable for scriplet" New topic
Author

Not SetInterval() is applicable for scriplet

satyaprasad veeramsetti
Greenhorn

Joined: Dec 21, 2012
Posts: 28
Hi Friends,
I want to display message for every five seonds in Server side using scriplet. For this, i have added below code.

<html>
<head>

<script type="text/javascript">
setInterval(function(){
show();
}, 5000);

function show(){

<%
System.out.println("Five Seconds");

%>
}
</script>
</head>
<body>

</body>
</html>






But it is showing the message "Five Seconds" only once. if we put alert() inside show() method, i displays alert message for every 5 seconds.
i.e.
<script type="text/javascript">
setInterval(function(){
show();
}, 5000);

function show(){

<%
System.out.println("Five Seconds");

%>
}
</script>



I dont now the reason. Please help me.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

You cannot mix JSP code with JavaScript. Please read this article to understand how JSP operates and why this is impossible.

If you want to communicate with the server via JavaScript, you'll need to use Ajax.

So, what is it that you are actually trying to accomplish?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
jQuery in Action, 2nd edition
 
subject: Not SetInterval() is applicable for scriplet