try on the client sidevar xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.4.0");
xmlHTTP.open("POST","http://myserver/save.jsp", false);
xmlHTTP.setRequestHeader("Content-Type","text/xml");
xmlHTTP.send(xmlDoc.xml);on the server, get the text input stream and load it into your dom object

解决方案 »

  1.   

    to 无为:
      我就是不知道JSP页如何接收这个xmlDoc.xml,是作为String,还是作为InputStream呢?应该怎么写呢?能否简短地写两句看看,谢谢
      

  2.   

    BufferedReader in = request.getReader();
    String line;
    while ((line = in.readLine()) != null)
    {
    //....
    }
      

  3.   

    ServletRequest ClassgetInputStream
    public ServletInputStream getInputStream()
                                      throws java.io.IOException
    Retrieves the body of the request as binary data using a ServletInputStream. Either this method or getReader() may be called to read the body, not both.
    Returns:
    a ServletInputStream object containing the body of the request
    Throws:
    java.lang.IllegalStateException - if the getReader() method has already been called for this request
    java.io.IOException - if an input or output exception occurred
      

  4.   

    getInputStream
    public ServletInputStream getInputStream()
                                      throws java.io.IOException
    Retrieves the body of the request as binary data using a ServletInputStream. Either this method or getReader() may be called to read the body, not both.
    Returns:
    a ServletInputStream object containing the body of the request
    Throws:
    java.lang.IllegalStateException - if the getReader() method has already been called for this request
    java.io.IOException - if an input or output exception occurred
      

  5.   

    我写了两个文件// 88.html
    <SCRIPT LANGUAGE="JavaScript">
      var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
      var xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP.4.0");
      
      xmlDoc.async=false;  xmlDoc.load("web.xml");  if (xmlDoc.readyState==4)
      {
        if(xmlDoc.parseError.errorCode!=0)
    {
      alert(xmlDoc.parseError.reason)
    }
        else
    {
          xmlHTTP.open("GET","save.jsp",false);
          xmlHTTP.send(xmlDoc.xml);
          window.alert("Done");
        }
      }
    </SCRIPT>// save.jsp
    <%@page import="java.io.*"%>
    <%
      BufferedReader in = request.getReader();
      String line;
      String realPath = config.getServletContext().getRealPath("12345.txt");  File f=new File(realPath);
      FileWriter fw=new FileWriter(f);  try
      {
        while ((line = in.readLine()) != null)
        {
          fw.write(line);
        }
        fw.close();
      }
      catch(Exception e)
      {
        e.printStackTrace();
      }
      finally
      {
        out.println("Done");
      }
    %>两个文件在同一个目录下,我运行了两个文件都没有错,可是运行的时候为什么没有12345.txt文件生成呢?另外,象xmlHTTP这样的请求,不刷新页面,我应该如何调试程序呢?
      

  6.   

    我写了两个文件// 88.html
    <SCRIPT LANGUAGE="JavaScript">
      var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
      var xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP.4.0");
      
      xmlDoc.async=false;  xmlDoc.load("web.xml");  if (xmlDoc.readyState==4)
      {
        if(xmlDoc.parseError.errorCode!=0)
    {
      alert(xmlDoc.parseError.reason)
    }
        else
    {
          xmlHTTP.open("GET","save.jsp",false);
          xmlHTTP.send(xmlDoc.xml);
          window.alert("Done");
        }
      }
    </SCRIPT>// save.jsp
    <%@page import="java.io.*"%>
    <%
      BufferedReader in = request.getReader();
      String line;
      String realPath = config.getServletContext().getRealPath("12345.txt");  File f=new File(realPath);
      FileWriter fw=new FileWriter(f);  try
      {
        while ((line = in.readLine()) != null)
        {
          fw.write(line);
        }
        fw.close();
      }
      catch(Exception e)
      {
        e.printStackTrace();
      }
      finally
      {
        out.println("Done");
      }
    %>两个文件在同一个目录下,我运行了两个文件都没有错,可是运行的时候为什么没有12345.txt文件生成呢?另外,象xmlHTTP这样的请求,不刷新页面,我应该如何调试程序呢?
      

  7.   

    out.println(realPath);看看是什么,是否有问题?
      

  8.   

    哦,刚才是路径的问题,现在运行save.jsp,12345.txt文件是生成了,是个空的运行88.html,请求是发送了,但是save.jsp好像没有接受到xmlHTTP请求我是这样想的,在客户端用xmlHTTP请求提交一个内容为xml的二进制流去服务器,服务器根据这个流,在硬盘上生存一个xml文件。你看我上面的两个文件应该如何修改,才能达到这个目的呢?
      

  9.   

    while ((line = in.readLine()) != null)
    {
      out.println(line); //看看有没有东西。如果没有即没有收到XML
      fw.write(line);
    }
      

  10.   

    在save.jsp页面中out.println(line);没有显示,即没有收到xml流但是88.html中的window.alert(xmlHTTP.responseText);可以接收到返回的字符串"Done"
      

  11.   

    Servlet中我们是这样处理的,不知Jsp怎样,不过应该大同小异
            response.setContentType( "text/xml" );        // get the communication channel with the requesting client
            PrintWriter out = response.getWriter();        try
            {
                ServletInputStream servletInputStream = request.getInputStream();
                int contentLength = request.getContentLength();
                byte[] b = new byte[ contentLength ];
                int once = 0;
                int total = 0;            while ( ( total < contentLength ) && ( once >= 0 ) )
                {
                    once = servletInputStream.read( b, total, contentLength );
                    total += once;
                }            if ( total > 0 )
                {
                    XMLFileVisitor xmlData = new XMLFileVisitor();
                    Hashtable values = xmlData.getExecCommandAttributes(
                                               new StringBufferInputStream(
                                                       new String( b, 0, total ) ),
                                               "root" );
                    String command = values.get( "command" ).toString();                // 上传文件
                    if ( command.equals( "1" ) )
                    {
                        String fileContent = values.get( "fileContent" ).toString();
                        byte[] c = stringToHex( fileContent );
                        String filename = SystemVar.getSerialNumberString() +
                                          values.get( "filename" ).toString();
                        File file = new File( SystemVar.getWorkflowUploadPath() +
                                              filename );
                        BufferedOutputStream out1 = new BufferedOutputStream(
                                                            new FileOutputStream(
                                                                    file ) );
                        out1.write( c );
                        out1.close();                    // 输出结果
                        out.println( SystemVar.getWorkflowDownloadPath() +
                                     filename );
                        out.close();                    return;
                    }
                }
            }
            catch ( Exception exp )
            {
                exp.printStackTrace();
            }
      

  12.   

    因为xmlHttp在Client端没进行Base64编码,所以上传过程中是以16进制数据的Ascii形式进行的,上传以后还需要将它转为Byte形式;如果你要优化,可以进行Base64编码。
      

  13.   

    真是活活气死
    不是Java的问题
    是var xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP.4.0");
    这一句,我把它改成了
    var xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
    就OK了,真是FAINT,要用原始的版本
      

  14.   

    我把改真的文件贴出来// 88.html
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <SCRIPT LANGUAGE="JavaScript">
    function run()
    {
      var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
      var xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
      
      xmlDoc.async=false;
      
      xmlDoc.load("web.xml");  if (xmlDoc.readyState==4)
      {
        if(xmlDoc.parseError.errorCode!=0)
    {
      alert(xmlDoc.parseError.reason);
      return false;
    }
        else
    {
          xmlHTTP.open("GET","save.jsp",false);
          xmlHTTP.send(xmlDoc.xml);
         
          window.alert(xmlHTTP.responseText);
        }
      }
    }
    </SCRIPT>
    </HEAD>
    <BODY><INPUT id=button1 type=button value=发送xmlHTTP请求 name=run onClick="run()">
    </BODY>
    </HTML>
    // save.jsp
    <%@page import="java.io.*"%>
    <%
      BufferedReader in = request.getReader();
      String line;
      String realPath = config.getServletContext().getRealPath("\\OATree\\12345.txt");  File f=new File(realPath);
      FileWriter fw=new FileWriter(realPath);
      BufferedWriter bw=new BufferedWriter(fw);
      try
      {
        while ((line = in.readLine()) != null)
        {
      out.println(line);
          bw.write(line);
      bw.newLine();
        }
        bw.close();
    fw.close();
      }
      catch(Exception e)
      {
        e.printStackTrace();
      }
      finally
      {
        out.println("Mission Completed");
      }
    %>
      

  15.   

    呵呵,我们都是来听 Patrick_DK(疾风摩郎) 兄讲课的
      

  16.   

    哪里啊,我是刚开始碰这东西,还是半懂不懂的好像Java版这么写的人不太多啊跟贴的人很少