0

Ok, so I have a jsp web page that shows me what are the courses that I am registered to. the jsp code that is performed in the begining of the page:

<div>
<%
    String username = request.getUserPrincipal().getName();
    Iterable<Course> avCourses = ORM.getAvailableCourses(username);
%>
</div>
<form id="avCoursesForm">
                <fieldset>
                    <legend>Available courses: </legend>
                    <table class="coursesTable">
                    <tr id="firstTr" style="display: none;">
                    <td class="blueBorder" style="width:5%;"></td>
                    <td class="blueBorder" style="width:20%;"><b>Course name</b></td>
                    <td class="blueBorder" style="width:15%;"><b>Course id</b></td>
                    <td class="blueBorder" style="width:5%;"><b>Credit points</b></td>
                    <td class="blueBorder" style="width:10%;"><b>Group number</b></td>

                    </tr>
                    <%
                        Iterator<Course> iter = avCourses.iterator();
                        int size = 0;
                        while(iter.hasNext())
                        {
                            Course course = iter.next();
                            %>
                            <tr id="trOfTable<%=size%>" style="display: none;">
                                <td class="blueBorder" style="width:5px;"> 
                                    <input type="checkbox" name="option" value="<%=course.courseName%>" />
                                </td>
                                <td class="blueBorder"> 
                                    <a href=# onclick="getPage('<%=request.getContextPath() %>', '<%=course.courseName %>');">
                                    <%=course.courseName%> </a>
                                 </td>
                                 <td class="blueBorder">
                                    <%=course.courseId%>
                                 </td>
                                 <td class="blueBorder">
                                    <%=course.creditPoints%>
                                 </td>
                                 <td class="blueBorder">
                                    <%=course.groupNum%>
                                 </td>

                            </tr>
                            <%
                            size++;
                        }
                    %>
                    </table>
                </fieldset>
</form>

the function getAvailableCourses() is at ORM.java file (this file queries the DB).

My goal is to check the database every X seconds to see if a certain course is still available for registration. I don't know how to do that. Can you help me? In other words, I want to asynchronously check the database and accordingly refresh parts of the page (unavailable course will disappear and new available courses will appear).

tnx, Itamar.

  • Learn how to use [servlets](http://stackoverflow.com/tags/servlets/info) and [ajax](http://stackoverflow.com/questions/4112686/how-to-use-servlets-and-ajax). – BalusC Jul 14 '11 at 18:07

1 Answers1

0

You can use javascript setTimeout. This method call a target javascript function after every x times. Here is the pseudo code

<script type="text/javascript">

function checkCourse(){
   var courseId = 5; //for example
   // call servlet using ajax to check course is available or not.
  callServlet(); // you have to implement the callServlet
}

var x = 2000;
setTimeout("checkCourse()",x);
</script>
MAK Ripon
  • 1,065
  • 4
  • 14
  • 27