String strXML = "<?xml version='1.0' encoding='UTF-8' ?><logusers><loguser><qiname>"
+ qiname
+ "</qiname><user>"
+ username
+ "</user><pass>"
+ password + "</pass></loguser></logusers>";
String callURL = "http://unicom.chineseserver.net:3385/Corsend/login.aspx";
if (username != "" && password != "") {
}
在上面的if块里怎样发送xml
在ASP里可以这样写:代码如下:
set Https=server.createobject("MSXML2.XMLHTTP")
Https.open "post","http://unicom.chineseserver.net:3385/Corsend/login.aspx",false
Https.send strhtml但是在JSP里这么写??

解决方案 »

  1.   

    看看以下这个方法,是我之前写得一个类可以直接用来发xml数据,
    public static String getReponse(String url, String para, String method){
     String rtn = "";
     boolean isGet = (method == null) || method.trim().equals("") 
    || method.trim().equalsIgnoreCase("get");

     PrintWriter xmlOut = null;
     URL urlObj = null;
     HttpURLConnection acon = null;
     try{
    urlObj = new URL(url);
    acon = (HttpURLConnection) urlObj.openConnection();
    acon.setAllowUserInteraction(false);

    if (isGet) {
    acon.setRequestMethod("GET");                
    } else {
    acon.setRequestMethod("POST");
    acon.setRequestProperty("Content-Type", "application/xml");
    }

    acon.setDoOutput(true);
    acon.setDoInput(true);
    acon.setUseCaches(false);            

    if(!isGet){
    //写入xml参数
    xmlOut = new java.io.PrintWriter(acon.getOutputStream());
    xmlOut.write(para);
    xmlOut.flush();
    }
    long st = System.currentTimeMillis();
    if (acon.getResponseCode() >= 400) {              
        rtn = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><servlet-exception>";
        rtn += "HTTP response: " + acon.getResponseCode() + "\n"
            + URLDecoder.decode(acon.getResponseMessage(), "UTF-8");
        rtn += "</servlet-exception>";                            
    } else {
    //读出结果
    StringBuffer sb = new StringBuffer();
    int c;
    InputStream in = acon.getInputStream();

    while ((c = in.read()) != -1)
    sb.append((char)c);

    in.close();    
    rtn = sb.toString();
    }

    rtn = new String(rtn.getBytes("ISO8859-1"), "UTF-8");
    //System.out.println("GisRequester>>:" + (System.currentTimeMillis() - st));
     }catch(Exception e){
    e.printStackTrace();
     }  
    return rtn; 
    }
    不懂得话可以google一下
      

  2.   

    上面的代码全都是在JSP页面里的Java代码块里,即<% %>
    该怎么写?