你的User是由XSD或DTD生成的么,或者是有相应的Annotation修饰里面相应字段吗
而且必须保证User类没有@Xmlroot这个annotation的话就可以如果User类有@Xmlroot这个annotation的话,就可以直接unmarshal得到User类的对象 JAXBContext jc = JAXBContext.newInstance("edu.xiyou.xml");
Unmarshaller u = jc.createUnmarshaller();
FileInputStream f = new FileInputStream("f:/eclipse/workspace/Web/data.xml");
User usrs = (User) u.unmarshal(f);
而且必须保证User类没有@Xmlroot这个annotation的话就可以如果User类有@Xmlroot这个annotation的话,就可以直接unmarshal得到User类的对象 JAXBContext jc = JAXBContext.newInstance("edu.xiyou.xml");
Unmarshaller u = jc.createUnmarshaller();
FileInputStream f = new FileInputStream("f:/eclipse/workspace/Web/data.xml");
User usrs = (User) u.unmarshal(f);
可是我直接用User usrs = (User) u.unmarshal(f); 的话
会出现An exception occurred processing JSP 提示。这是怎么回事,必须要捕捉这个异常吗,还是说哪里还有问题,因为在编组的时候就没有出现要捕捉异常的情况。。
谢谢。。