使用Ajax从JSP到数据库获取时间戳信息的麻烦

时间:2014-06-26 00:16:24

标签: java javascript ajax jsp java-ee

我正在使用Ajax从两次点击检索已用时间并将其存储在一个表中,我试图在每次点击同一个表之后显示文本。下面是我的servlet和JSP。有人可以提供一些意见或解释吗?

    HttpSession session = request.getSession();

    String responsetime = request.getParameter("responsetime");
    String stimName = request.getParameter("stimName");
    String SID = request.getParameter("stimID");
    String AR = request.getParameter("Act_Response");

    LogInfo log = new LogInfo();
    log.setUser_Response(responsetime);
    log.setStimName(stimName);
    log.setStimName(SID);
    log.setStimName(AR);
    logDb.insert(log);

    logDb.selectStim(responsetime);

    session.setAttribute("log", log);

    String url = "/TestCaseRun.jsp";
    RequestDispatcher dispatcher
            = getServletContext().getRequestDispatcher(url);
    dispatcher.forward(request, response);
}

  var startTime;
                 function imageLoaded()
                 {
                     startTime = (new Date()).getTime();
                     document.getElementById('mybutton').disabled = false;
                 }
                 function submitUp() {
                     var endTime = (new Date()).getTime();
                     var elapsed = endTime - startTime;
                     submitAjaxRequest(elapsed);
                     alert("elapsed time: " + elapsed);
                 }
                 function submitDown() {
                     var endTime = (new Date()).getTime();
                     var elapsed = endTime - startTime;
                     submitAjaxRequest(elapsed);
                     alert("elapsed time: " + elapsed);
                 }

                 function submitAjaxRequest(timeelapsed) {
                     $.ajax({
                         type: "post", // Request type
                         url: "AjaxServlet", //Request URL or Servlet mapping URL
                         data: "timeelapsed" + timeelapsed, // Request Data to send
                         success: function(msg) { // On Successful
                             $('#srverResponse').text(msg);
                         }
                     });
                 }
   <input type="image" onclick="submitDown();" src="images.png>

0 个答案:

没有答案