String from Java Servlet to HTML via jQuery

String from Java Servlet to HTML via jQuery

Hey,

I have some problems with jQuery:

I want to generate dynamic html code via java serlvets.

from the class LightServlet

  1. public void getAllLights(HttpServletRequest request,
  2.             HttpServletResponse response) throws IOException,
  3.             NumberFormatException, InvalidSyntaxException {
  4.         response.setContentType("text/xml");
  5.         PrintWriter out = response.getWriter();
  6.         out.println("<div><report>");
  7.         for (int x = 0; x < l.getLightAmount(); x++) {
  8.            
  9.             String status;
  10.             if (l.checkLight(x) == true) {
  11.                 status = "on";
  12.             } else
  13.                 status = "off";
  14.               out.print("<form name='form' type='get' method='post'>");
  15.               out.print("<input type='button' class='setLampsClass' name='setLampID' "
  16.               + "id='setLampID_"+x+"' onclick='setlamp(" + x + ");' value='Set your light'/></form>");
  17.         }
  18.         out.println("</report></div>");
  19.         out.flush();
  20.         out.close();
  21.        
  22.    
  23.         out.flush();
  24.         out.close();
  25.     }

The code will be generated and I can see the code via firebug:

  1. <report>
  2. <form name="form" type="get" method="post">
  3.       <input type="button" class="setLampsClass" name="setLampID" id="setLampID_0" onclick="setlamp(0);" value="Set your light"/>
  4. </form>
  5. <form name="form" type="get" method="post"><input type="button" class="setLampsClass" name="setLampID" id="setLampID_1" onclick="setlamp(1);" value="Set your light"/></form><form name="form" type="get" method="post"><input type="button" class="setLampsClass" name="setLampID" id="setLampID_2" onclick="setlamp(2);" value="Set your light"/></form><form name="form" type="get" method="post"><input type="button" class="setLampsClass" name="setLampID" id="setLampID_3" onclick="setlamp(3);" value="Set your light"/></form><form name="form" type="get" method="post"><input type="button" class="setLampsClass" name="setLampID" id="setLampID_4" onclick="setlamp(4);" value="Set your light"/></form></report>

However the div tag, in which the generated html code should be inserted to, remains empty.

jQuery Function:

  1.   $("#getAllLights").click(function() {
  2.         $.post("LightServlet", {
  3.             ALL : 1
  4.         }, function(xml) {
  5.             $("#all").html($("report", xml).text());
  6.         });
  7.     });

I think, the problems should be in the jQuery code, because it works with normal strings without any html tags.

Thanks!