0
我想寫一個servlet,它將通過STRUTS2中的POST將XML文件(xml格式的字符串)發送到另一個servlet。我想讀Struts2中從另一個Servlet發送的流請求
servlet,它會發送一個XML文件:
String requestStr = "...........xml text........";
URLConnection con = new uRL("http://192.168.1.74/Project1/Request").openConnection();
con.setDoOutput(true);
OutputStream xmlResp = con.getOutputStream();
xmlResp.write(requestStr.getBytes("UTF-8"));
xmlResp.flush();
xmlResp.close();
servlet,它會recive一個XML文件:
InputStream in=req.getInputStream();
StringBuffer xmlStr=new StringBuffer();
int d;
while((d=in.read()) != -1){
xmlStr.append((char)d);
}
System.out.println("xmlStr1--"+xmlStr.toString());
int iCont=req.getContentLength();
return xmlStr.toString();
在上述情況下的InputStream:in.read返回-1但INT ICONT = REQ .getContentLength(); iCont返回值1335 ....!
上面的代碼在非struts環境中檢查時工作正常.....?
上述方法正在爲我工作....在struts2 ... :-) – Warrior 2011-03-18 11:41:14
不適合我。 – 2016-04-05 08:50:44