你的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); 

解决方案 »

  1.   

    不好意思写错了,不是@Xmlroot是@XmlRootElement这个Annotation
      

  2.   

    我使用XSD生成的类,@XmlRootElement的注释在Collection里面
    可是我直接用User usrs = (User) u.unmarshal(f); 的话
    会出现An exception occurred processing JSP 提示。这是怎么回事,必须要捕捉这个异常吗,还是说哪里还有问题,因为在编组的时候就没有出现要捕捉异常的情况。。
    谢谢。。
      

  3.   

    我不是很了解你的data.xml是什么样子的,你把这段程序放一个普通的含main的程序里去调试一下,就知道了,看看到底是出现什么问题,这样也可以确定是不是这里出的问题@XmlRootElement不在User类里的话,就不能用User usrs = (User) u.unmarshal(f);