wood burning stoves 2.0*
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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: 61066
    
  66

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]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not SetInterval() is applicable for scriplet