兄弟问错地方了吧???
这个是你的java代码错误,和struts有冲突或者不符合吧?而不是js代码错误

解决方案 »

  1.   

      String xml = readXMLFromRequestBody(request); 
     System.out.println("xml="+xml);
      这里开始就错掉了,你这里应该还没有获得到xml,你没发现后面打出来的报错信息吗
     xml= 
    [Fatal Error] :-1:-1: Premature end of file. 
    SAXException: org.xml.sax.SAXParseException: Premature end of file. 
    java.lang.NullPointerException 
    at dwr.struts.action.ProAction.send(ProAction.java:75) xml根本就没有取到值 ,所以根据xml生成的xmlDoc 也是null,然后就
    catch(SAXException e) { 
                      System.out.println("SAXException: " + e); 
                  } 
    这个异常啦.
    at dwr.struts.action.ProAction.send(ProAction.java:75) 
    这句主要是因为
    NodeList selectedPetTypes = xmlDoc.getElementsByTagName("type"); 
    xmlDoc是null的,所以这里才也会报个空指针异常
      

  2.   

    但是在Servlet里面就是好的呢?
      

  3.   

      InputStream xml = request.getInputStream();//readXMLFromRequestBody(request); 修改
               System.out.println("xml="+xml); 
                  Document xmlDoc = null; 
                  try { 
                      xmlDoc =  
                              DocumentBuilderFactory.newInstance().newDocumentBuilder() 
                              .parse(xml); 
                  } 
                  catch(ParserConfigurationException e) { 
                      System.out.println("ParserConfigurationException: " + e); 
                  } 
                  catch(SAXException e) { 
                      System.out.println("SAXException: " + e); 
                  }private String readXMLFromRequestBody(HttpServletRequest request){ //不要了
            StringBuffer xml = new StringBuffer(); 
            String line = null; 
            try { 
                BufferedReader reader = request.getReader(); 
                while((line = reader.readLine()) != null) { 
                    xml.append(line); 
                } 
            } 
            catch(Exception e) { 
                System.out.println("Error reading XML: " + e.toString()); 
            } 
            System.out.println(xml.toString()); 
            return xml.toString(); 
        } 
      

  4.   


    按照你的说法,还是不行,但是已经可以获取xml的值了
    输出如下:
    xml=org.apache.coyote.tomcat5.CoyoteInputStream@45484a
    [Fatal Error] :-1:-1: Premature end of file.
    SAXException: org.xml.sax.SAXParseException: Premature end of file.
      

  5.   

    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");     
    把这个去掉看看.
    createXML(); 
    这个让我看看,是不是XML的事.
      

  6.   

    request.setCharacterEncoding("GBK");
    这个写了没有.
    没遇到过帮不了你.