日期:2014-05-17 浏览次数:20745 次
<% Element root= null; Element student= null; Element number= null; Element name= null; Element age= null; root = new Element("student-info"); //生成根元素:student-info student = new Element("student"); //生成元素:student,该元素中将包含元素number,name,age number = new Element("number"); name = new Element("name"); age = new Element("age"); Document doc = new Document(root); //将根元素植入文档doc中 number.setText("001"); name.setText("lnman"); age.setText("24"); student.addContent(number); student.addContent(name); student.addContent(age); root.addContent(student); Format format = Format.getCompactFormat(); format.setEncoding("gb2312"); //设置xml文件的字符为gb2312 format.setIndent(" "); //设置xml文件的缩进为4个空格 XMLOutputter XMLOut = new XMLOutputter(format);//在元素后换行,每一层元素缩排四格 XMLOut.output(doc, new FileOutputStream("studentinfo.xml")); %>
------解决方案--------------------
错误信息贴出来
------解决方案--------------------
org.apache.jasper.JasperException: /index.jsp(2,0) Page directive must not have multiple occurrences of pageencoding
index.jsp第二行是不是又引入<%@ page language="java" import="org.jdom.*" pageEncoding="GBK"%>了,只能设定一次编码。
------解决方案--------------------
方法中用到包的方法都没有报错,说明包肯定导进去了