java获取接收POST过来的XML数据包,使用request.getInputStream() 和 request.getReader()
struts2 Action中获取request, response对象的方法
ActionContext ctx = ActionContext.getContext();
HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);
HttpServletResponse response = (HttpServletResponse)ctx.get(ServletActionContext.HTTP_RESPONSE);
//ServletActionContext.APPLICATION;
//ServletActionContext.SESSION;
//ServletActionContext.PAGE_CONTEXT;
struts2 中使用request.getInputStream()获取POST数据
BufferedReader br = new BufferedReader(new InputStreamReader((ServletInputStream)request.getInputStream()));
String line = null;
StringBuilder sb = new StringBuilder();
while((line = br.readLine())!=null){
sb.append(line);
}
BufferedReader br = new BufferedReader(new InputStreamReader((ServletInputStream)request.getInputStream()));
String line = null;
StringBuilder sb = new StringBuilder();
while((line = br.readLine())!=null){
sb.append(line);
}
java的post
URL url = new URL(urlBuf);
HttpURLConnection httpURLConnection = (HttpURLConnection) url
.openConnection();
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
httpURLConnection.setRequestMethod("POST"); httpURLConnection.setConnectTimeout(5000);
httpURLConnection.setReadTimeout(5000);
httpURLConnection.connect();
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
httpURLConnection.getOutputStream(), "GBK"));
out.write(word);
out.flush();
URL url = new URL(urlBuf);
HttpURLConnection httpURLConnection = (HttpURLConnection) url
.openConnection();
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
httpURLConnection.setRequestProperty("content-type", "text/html");
httpURLConnection.setRequestMethod("POST");httpURLConnection.setConnectTimeout(5000);
httpURLConnection.setReadTimeout(5000);
httpURLConnection.connect();
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
httpURLConnection.getOutputStream(), "GBK"));
out.write(word);
out.flush();