1 Replies - 2398 Views - Last Post: 25 June 2014 - 04:25 PM

#1 nat0001   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 23-February 14

Trouble with getting timestamp info from JSP to database using Ajax

Posted 25 June 2014 - 04:24 PM

I am using Ajax to retrieve elapsed time from two on clicks and store it in a table, I am trying to get text to appear after each click from that same table as well
Any input or explanation would be greatly appreciated.

Thanks in advance
-Cheers

This is my servlet

    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 = "/home.jsp";
        RequestDispatcher dispatcher
                = getServletContext().getRequestDispatcher(url);
        dispatcher.forward(request, response);
    }

This is my JSP

               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="image.png>



this is my current error:
java.lang.IllegalStateException: Cannot forward after response has been committed

Is This A Good Question/Topic? 0
  • +

Replies To: Trouble with getting timestamp info from JSP to database using Ajax

#2 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12742
  • View blog
  • Posts: 45,924
  • Joined: 27-December 08

Re: Trouble with getting timestamp info from JSP to database using Ajax

Posted 25 June 2014 - 04:25 PM

Moved to our Java EE forum. Please make sure to post JSP, Servlets, Struts, and related questions in the Java EE forum in the future.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1