现在做一个系统,给另一个公司提供服务,他们传递一个XML字符串报文我们,我们做处理不是很清楚,报文为什么传递的直接是XML的内容字符串。难道这就是所谓的报文?还有我们返回的也是XML报文。JSON现在这么流行 为什么不用JSON传递呢??由于不是直接参与开发的,我看不了源码,好像我们这边用到了dom4j
麻烦懂的,给我讲解下
麻烦懂的,给我讲解下
解决方案 »
- 查询大数据时出现org.hibernate.exception.GenericJDBCException: Cannot open connection
- Hibernate 中持久化对象的问题
- 在线等、、给分、、、java script 一个方法验证多个表单不能为空 并在表单后面显示相关信息?????????
- 想软考,但计算机基础不好,前辈们进来给指点指点呀,还有,软考的证含金量究竟怎么样?
- 高分求购LMS的实例
- tomcat的缺省运行目录咋的了
- 反序列化的问题
- 请问如何取得系统时间?
- 请推荐几本学习J2EE和EJB的经典书籍,定给高分酬谢
- tomcat报错啊!!求助
- SSH2结构下openSessionInView无效,求指教!查了一天了,谢谢大家了...
- tomcat 6.0 配置虚拟路径 报错
package nc.plugin.test; /**
* 此处插入类型说明。
* 创建日期:(2004-12-5 15:49:22)
* @author:Administrator
*/
import java.lang.*;
import java.util.*;
import java.sql.*;
import java.io.*;
import java.net.*; public class PostFile {
HttpURLConnection connection = null;
/**
* PostFile 构造子注解。
*/
public PostFile() {
super();
}
/**
* PostFile 构造子注解。
*/
//获得HTTP连接
public HttpURLConnection getConnection(String url) throws Exception{ try {
URL realURL = new URL(url);
URLConnection conn = realURL.openConnection(); conn.setRequestProperty("Content-type", "text/xml");
connection = (HttpURLConnection) conn;
connection.setDoOutput(true);
connection.setRequestMethod("POST");
System.out.println("获得连接"+url);
} catch (MalformedURLException mex) {
mex.printStackTrace();
throw mex;
} catch (ProtocolException pex) {
pex.printStackTrace();
throw pex;
} catch (IOException iex) {
iex.printStackTrace();
throw iex;
}
return connection;
} //调用过程,方法入口.
public static void main(String[] args){
PostFile pf = new PostFile(); String str=null;
String url="http://192.168.16.46:9088/service/XChangeServlet?account=004&receiver=1@1-0002";
String[] m_allSelectedFiles = {"D:/voucher/101200012009070063.xml"}; for (int i = 0; i < m_allSelectedFiles.length; i++) {
//获得连接
try{
pf.getConnection(url);
pf.sendFile(new File(m_allSelectedFiles[i]),"gb2312");
str += "\n" + pf.receiveResponse("gb2312"); }catch(Exception e){
System.out.println("getConnection Exception");
System.out.println("aaaaaaaaaaaaaa");
}
//发送文件
//接收回执 System.out.println(str);
} // end for
} //发送文件
public BufferedReader readFile(String file) throws Exception{
BufferedReader in1=null;
try {
//从文件获得输入
in1=new BufferedReader(new InputStreamReader(new FileInputStream(file),"gb2312"));
//循环获得文件中的内容,并out发出 } catch (Exception ex) {
ex.printStackTrace();
throw ex;
}
return in1;
}
//获取数据响应
public String receiveResponse(String output_coding) {
BufferedReader in;
StringBuffer response = new StringBuffer();
//File file=null;
try {
//此处获得响应回执
in = new BufferedReader(new InputStreamReader(connection.getInputStream(),output_coding));
String line = ""; while ((line = in.readLine()) != null) {
//line = new String(line.getBytes("utf-8"),"gb2312");
response.append(line + "\n");
//System.out.println(line);
}
in.close();
} catch (Exception exception) {
exception.printStackTrace();
}
return response.toString();
}
//发送文件
public void sendFile(File file,java.lang.String input_coding) throws Exception{
try {
PrintWriter out = new PrintWriter(connection.getOutputStream());//获得一个输出流
//从文件获得输入
BufferedReader in1=new BufferedReader(new InputStreamReader(new FileInputStream(file),input_coding));
//循环获得文件中的内容,并out发出 String s;
while ((s = in1.readLine()) != null) {
out.println(s); out.flush();
}
out.close();
System.out.println("已经成功发送XML文件!");
}catch (UnknownHostException uhe){
uhe.printStackTrace();
throw uhe;
} catch (Exception ex) {
ex.printStackTrace();
throw ex;
}
} }
这是用http调用servlet的方法.
服务器端写一个servlet处理xml文件就行.
明白了吗:有什么可以给我留言
<textarea rows="30" cols="150" id="queryXml" name="queryXml"></textarea> <br><br>
<input type="button" value="扫描修改" onClick="t1('servlet/ImageScanUpdateServlet')">我们在textarea输入框黏贴一段XML文本内容提交,返回相应的结果或者操作界面问:
1、这是在前台界面XML是手写的 如果需要程序生成XML是不是用dom4j呢2、XML是不是比json更加通用,好像json不能支持桌面程序