3 Replies Latest reply on Apr 16, 2007 3:20 PM by dvohra21

    AJAX with JSP error

    572326
      hi
      I'm trying to run a simple AJAX program with JSP using JDeveloper (jdevstudio10132) im getting the expected result along with following error message and i pasted the actual coding below.

      ERROR MESAGE-------
      Request URI:/Application3-Project1-context-root/getcd.jsp

      Exception:
      java.lang.IllegalStateException: Writer already retrieved at com.evermind.server.http.EvermindHttpServletResponse.getOutputStream(EvermindHttpServletResponse.java:880) at com.evermind.server.http.EvermindHttpServletResponse.getJspOutputStream(EvermindHttpServletResponse.java:875) at com.evermind.server.http.EvermindJSPWriter.initServletOut(EvermindJSPWriter.java:525) at com.evermind.server.http.EvermindJSPWriter.writeOut(EvermindJSPWriter.java:537) at com.evermind.server.http.EvermindJSPWriter.jspflush(EvermindJSPWriter.java:436) at com.evermind.server.http.EvermindJSPWriter.close(EvermindJSPWriter.java:406) at oracle.jsp.runtime.OracleJspRuntime.extraHandlePCFinally(OracleJspRuntime.java:1689) at getcd.jspService(_getcd.java:92) [getcd.jsp] at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59) at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:462) at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:598) at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:522) at javax.servlet.http.HttpServlet.service(HttpServlet.java:856) at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:712) at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:369) at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:865) at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:447) at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:215) at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:117) at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:110) at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260) at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:239) at oracle.oc4j.network.ServerSocketAcceptHandler.access$700(ServerSocketAcceptHandler.java:34) at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:880) at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303) at java.lang.Thread.run(Thread.java:595)


      ---JSPProgram---
      <%
      String s = request.getParameter("q");
      response.setContentType("text/xml");
      response.setHeader("Cache-Control", "no-cache");
      response.getWriter().write(s);
      %>

      -----------------------------------------------------------

      ------HTML---
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
      <html>
      <head>
      <!---<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"></meta>-->
      <title>Hello Ajax from file</title>
      <script src="helloAjax.js" type="text/javascript"></script>
      <script type="text/javascript">
      function doTheAjaxThing(str){
      var PAGE_SUCCESS = 200;
      var requestObject = xmlHttpRequestHandler.createXmlHttpRequest();
      requestObject.open("Get","getcd.jsp?q="+str,false);
      //requestObject.open("Get","servlet1?q="+str,false);
      requestObject.send(null);
      if (requestObject.readyState==4)
      {
      if(requestObject.status==PAGE_SUCCESS){
      var div_handle = document.getElementById("txtHint");
      if(div_handle){
      div_handle.innerHTML=requestObject.responseText;
      }
      }
      }
      else{
      alert ("Request failed");
      }
      }
      </script>
      </head>
      <body><form>
      Select a CD:
      <select name="cds" onchange="doTheAjaxThing(this.value)">
      <option value="one">One</option>
      <option value="two">Two</option>
      <option value="three">Three</option>
      </select>
      </form><p>
       
      </p><div id="txtHint">
      <b>Display</b>
      </div></body>
      </html>
      -----------------------------------------------------------------

      -------JAVA SCRIPT-------------
      var xmlHttpRequestHandler = new Object();
      xmlHttpRequestHandler.createXmlHttpRequest = function(){

      var XmlHttpRequestObject;
      if (typeof XMLHttpRequest != "undefined"){
      XmlHttpRequestObject = new XMLHttpRequest();
      }
      else if (window.ActiveXObject){
      // look up the highest possible MSXML version
      var tryPossibleVersions=["MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0",
      "MSXML2.XMLHttp.3.0",
      "MSXML2.XMLHttp", "Microsoft.XMLHttp"];

      for (i=0; i< tryPossibleVersions.length; i++){
      try{
      XmlHttpRequestObject = new ActiveXObject(tryPossibleVersions);
      break;
      }
      catch (xmlHttpRequestObjectError){
      //ignore
      }
      }
      }
      return XmlHttpRequestObject;
      }

      -------------------------------------------------------------------------------

      Message was edited by:
      user569323