1。就用那个土办法吧,好像还好用
2。传输dom对象,把dom对象序列化。
2。传输dom对象,把dom对象序列化。
解决方案 »
- import typeinfo.pets.*的问题
- 在action里面如何获取session的值?
- 讨论关于权限问题。
- 多张表如何实现sql语句拼接
- 模糊查找时:could not execute query
- jdbc能否执行sql脚本
- spring配置的list,pops问题不懂
- SQLSERVER2000下使用hibernate取blob类型的数据,报这样的一个错误,高手帮忙看看
- 我要突破自己---一位外企人的生活点滴!
- 我的ORACLE怎么连不上,帮忙啊!
- 请有经验的朋友讲讲学习和开发EJB要注意些什么,难点在那里!
- 请问谁知道怎么上http://sourceforge.net/???急!!!!
主 题: 如何通过Socket传输对象?
传对象到底是个什么概念啊:)
但是问题是dom对想怎么序列化啊
请给个例子看看:)
DELPHI(客户端)-CORBA-IIOP-RMI-JAVA(服务器)
我没做过,看理论上应该行得通的,不过技术复杂性是有点...
偶是判断有没有child,如果有,就嵌套
然后加上一些特殊的字符("<",">","\"等等)
还有回车、空格:)
看上去好烦啊
没有更好的办法?:)
能不能说具体点?
呵呵,我去查查先:)
result还有一个实现是resultStream,但是这个有没办法和node关联:(
那位知道的,请赐教
SAsura(SAsura) :jaxp用的是apache的解析器,请问你所说的是什么类什么函数?
一直等待:[email protected]
:)
明白了吧:)
{
byte[] bx = new byte[1];
try
{
ObjectOutputStream fin;
ByteArrayOutputStream b = new ByteArrayOutputStream();
fin = new ObjectOutputStream(b);
fin.writeObject(data);
fin.flush();
fin.close();
fin = null;
bx = new byte[b.size()];
bx = b.toByteArray();
}
catch(Exception e)
{
log(" bAppending/writing object data error : " + e.toString());
}
return bx;
} public static Object breaddato(byte[] data)
{
Object bx = new Object();
try
{
ObjectInputStream fin;
ByteArrayInputStream b = new ByteArrayInputStream(data);
fin = new ObjectInputStream(b);
bx = fin.readObject();
fin.close();
fin = null;
}
catch(Exception e)
{
log(" bAppending/writing object data error : " + e.toString());
}
return bx;
}
1。不规范,代码难于维护,不能体现xml的特性
2。有些字符在xml中要转意,不是手工代码可以轻松实现的
3。encoding问题通过socket传递xml信息,我有一些经验可以和你分享。
你有些经验吗?可否贴出来分享?期待!
路人甲
为什么我从你那里改过来的这一段东西会错呢?import java.io.*;public class ObjectWriter{ private static byte[] tempByte = new byte[1];
private static Object object = new Object(); public static void objectToByte(Object oIn,byte[] bOut){
try{
bOut = new byte[1];
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
ObjectOutputStream oOut = new ObjectOutputStream(byteOut);
oOut.writeObject(oIn);
oOut.flush();
oOut.close();
oOut = null;
bOut = new byte[byteOut.size()];
bOut = byteOut.toByteArray();
}catch(IOException ioe){
System.out.println(ioe.toString());
}
} public static void byteToObject(byte[] bIn,Object oOut){
try{
ByteArrayInputStream byteIn = new ByteArrayInputStream(bIn);
ObjectInputStream oIn = new ObjectInputStream(byteIn);
object = oIn.readObject();
oIn.close();
oIn = null;
}catch(IOException ioe){
System.out.println("IO Wrong here");
ioe.printStackTrace();
}catch(ClassNotFoundException cnfe){
System.out.println("Class Wrong there");
cnfe.printStackTrace();
}
} private void test1(){
String string1 = "eeeeeeeweqpiaxzc;lvasdkl33336655365**!!!!!!";
objectToByte(string1,tempByte);
byteToObject(tempByte,object);
System.out.println((String)object);
} public static void main(String[] args){ ObjectWriter objectOut = new ObjectWriter();
objectOut.test1();
}
}谢谢
我也想贴出来,可是码字要时间啊
期待你的贴字早点出来另外,我想问一下dom是不是不支持GBK(但支持gb2312),jdom我还没有用过,不知道支不支持GBK?
你看看我以前做过的程序
import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.util.*;
import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
import javax.xml.transform.dom.*;
import org.apache.xalan.serialize.Serializer;
import org.apache.xalan.serialize.SerializerFactory;
import org.apache.xalan.templates.OutputProperties;
public class AddRecord4
{
public static void main(String[] args)
{
//System.out.println("Hello World!");
String name="fancy";
DocumentBuilder parser;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try
{
parser = factory.newDocumentBuilder();
Document doc = parser.parse("user.xml");
Element newlink=doc.createElement(name);
doc.getDocumentElement().appendChild(newlink);
outputDoc(doc);
}
catch (Exception e)
{
//to do it
}
} public static void outputDoc (Document doc)
{
DOMSource domSource = new DOMSource (doc);
//Input. Document is an extended class of Node, and therefore can
//be used here.
DOMResult domResult = new DOMResult();
// Output.
try
{
TransformerFactory tf=TransformerFactory.newInstance();
// Get a TransformerFactory.
Transformer t=tf.newTransformer ();
// Make a new Transformer from it
Properties properties = t.getOutputProperties();
properties.setProperty(OutputKeys.ENCODING,"GB2312");
//properties.setProperty(OutputKeys.METHOD,"html");
//properties.setProperty(OutputKeys.VERSION,"4.0");
//properties.setProperty(OutputKeys.INDENT,"no");
t.setOutputProperties(properties);
t.transform(domSource,domResult);
Serializer serializer = SerializerFactory.getSerializer
(OutputProperties.getDefaultMethodProperties("xml"));
Properties prop=serializer.getOutputFormat();
prop.setProperty("encoding","GB2312");
//prop.list(System.out);
serializer.setOutputFormat(prop);
File f = new File ("xuser4.xml");
FileOutputStream fos=new FileOutputStream(f);
serializer.setOutputStream(fos);
serializer.asDOMSerializer().serialize(domResult.getNode());
}
catch (Exception tce)
{
tce.printStackTrace();
}
}
}
对了,是把所有的obj都转成了byte[],但是为什么要这么复杂呢?简直就是重写tostring嘛。呵呵,说了半天,还是没有人能够方便的解决问题阿...
呵呵,最简单的就是一行:Object.toString()还是不能结贴:(
我关心的是哪个Object.toString()可以读取xml字符串。谢谢!
..XmlOutputter out = new XmlOutputter(" ", true);String strOut = out.outputString(dom);ref: http://www.jdom.org
gsh(cool98) :呵呵,你不知道java所有的class都是从object派生出来的吗?tostring是Document