我在一个项目中利用Stax Parser制作XML文件,使用以下代码。 我在通常的java申请中使用过这部法律,并在那里使用罚款。 但是,当我为塞莱特实施这一规定时,我不知道为什么不这样做。 我没有发现任何错误,但XML<>/strong>文档没有生成。
private static ServletContext sc;
public void init(ServletConfig config) throws ServletException {
// TODO Auto-generated method stub
sc = config.getServletContext();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String path = sc.getRealPath("/WEB-INF/xml");
System.out.println("Path ==>" + path);
XMLOutputFactory factory = XMLOutputFactory.newInstance();
File f = new File(path+"/atms.xml");
XMLStreamWriter writer = factory.createXMLStreamWriter(new FileOutputStream(f));
//Some more code
writer.writeStartDocument();
writer.writeStartElement("xxx");
writer.writeStartElement("yyy");
writer.writeStartElement("id");
writer.writeCharacters("1");
writer.writeStartElement("name");
writer.writeCharacters("Table");
writer.writeStartElement("price");
writer.writeCharacters("110");
writer.writeEndElement();
writer.close();
}