Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Not setInterval() is applicable for scriplet

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Not setInterval() is applicable for scriplet

    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 at first time. if we put alert() inside show() method, it 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 don't now the reason. Please help me.


  2. #2
    Junior Member
    Join Date
    Jan 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Not setInterval() is applicable for scriplet

    If you look at .java file generated for the index.jsp file, you can see that scriplets are written as is and the other lines are written to out.write.

    Hence you can see, your println only once.

    public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response)
    throws java.io.IOException, javax.servlet.ServletException {
    ...................

    out.write("<script type=\"text/javascript\">\r\n");
    out.write("setInterval(function(){\r\n");
    out.write("show();\r\n");
    out.write("}, 5000);\r\n");
    out.write("function show(){ \r\n");

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

    out.write("\r\n");
    out.write("}\r\n");

    ............
    }

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Not setInterval() is applicable for scriplet

    What is the solution for this problem

    --- Update ---

    Hi Haritha,
    I am from Hyderabad.


    Please solve my problem

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Not setInterval() is applicable for scriplet

    First, javascript != java, these are java forums - hence your thread has been moved. Second, javascript is client side, you cannot invoke server side processes unless explicitly done, say through ajax. If you wish to update the client page periodically, then do so using javascript to change the document.

Similar Threads

  1. Method is not applicable for the arguments
    By jbodary in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 23rd, 2012, 07:05 AM
  2. Replies: 1
    Last Post: April 19th, 2012, 02:46 AM
  3. Problem with inheritence? arguments not applicable
    By rbk in forum Object Oriented Programming
    Replies: 2
    Last Post: March 29th, 2011, 09:37 AM

Tags for this Thread