<%--List8_7_1.jsp--%>
<%@ page import="foo.bar.foobar.Student,
                 java.io.*,
                 org.exolab.castor.xml.Marshaller,
                 org.exolab.castor.xml.Unmarshaller,
                 org.exolab.castor.xml.ValidationException,
                 org.exolab.castor.xml.MarshalException"%>
<%@ page contentType="text/html;charset=GB2312" language="java" %>
<html>
  <head><title>使用XML文件存储持久化对象</title></head>
  <body>
  <%
      Student student1=new Student();
              student1.setSid(200001121);
              student1.setName("Anty");
              student1.setSchool("BIT");
              try {
                  Writer writer=new FileWriter("Student.xml");
                  Reader reader=new FileReader("Student.xml");
                  //将student1对象存入Student.xml文件中
                  Marshaller.marshal(student1,writer);
                  //将Student.xml中的对象读取出来，赋值给student2
                  Student student2=(Student)Unmarshaller.unmarshal(Student.class,reader);
                 //测试操作前后的值是否未变
                  System.out.println("student1==student2 : " + student1.equals(student2));
              } catch (IOException e) {
                  System.out.println("Failed to operate with Student.xml!");
                  e.printStackTrace();
              } catch (ValidationException e) {
                  System.out.println("Failed to validate the File!");
                  e.printStackTrace();
              } catch (MarshalException e) {
                  System.out.println("Failed to Marshal the object!");
                  e.printStackTrace();
              }

  %>
  </body>
</html>