开发者

How do I check my database every once in a while in a jsp page?

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>
                                 <开发者_StackOverflow中文版;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.


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜