Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not SetInterval() is applicable for scriplet

 
satyaprasad veeramsetti
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic