先贴出代码出来看看.
首先是一个Folders.xml文件:
<?xml version="1.0" encoding="gbk"?>
<Folders>
<Folder stepid="5" beginEid="1.0.0." endEid="8.0.0." folderId="88" folderName="文件夹一" />
<Folder stepid="5" beginEid="8.0.0." endEid="20.0.0." folderId="89" folderName="文件夹二" />
</Folders>
一下是解析XML文件的类.采用jdom解析.然后封装到一个Bean对象中.最后返回一个ArrayList集合.集合里面是一个个Bean对象. XmlConfig.Java
package JdBudget.OuterWeb.Config;
import java.util.*;
import java.io.*;
import JdBudget.OuterWeb.bean.*;
import JdBudget.OuterWeb.bean.Folder;
import org.jdom.output.*;
import org.jdom.input.*;
import org.jdom.*;
/**
* 操作xml的配置文件
* ItemId是报表文件Id号,Variant是报表参数(不包括公用参数)
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class XmlConfig {
public XmlConfig(){}
ArrayList dataList = null;
//解析Folders.xml
public ArrayList getFoldersInfo(String path) {
dataList = new ArrayList();
Folder dataValue = null;
try {
SAXBuilder builder = new SAXBuilder(false);
Document read_doc = builder.build(new FileInputStream(path));
Element root = read_doc.getRootElement();
List Folders = root.getChildren("Folder");
for (int i = 0; i < Folders.size(); i++) {
Element e = (Element) Folders.get(i);
dataValue = new Folder();
dataValue.setFolderId(e.getAttributeValue("folderId"));
dataValue.setEndEid(e.getAttributeValue("endEid"));
dataValue.setBeginEid(e.getAttributeValue("beginEid"));
dataValue.setStepid(e.getAttributeValue("stepid"));
System.out.println(e.getAttributeValue("folderId"));
System.out.println(e.getAttributeValue("folderName"));
System.out.println(e.getAttributeValue("endEid"));
System.out.println(e.getAttributeValue("beginEid"));
System.out.println(e.getAttributeValue("stepid"));
dataList.add(dataValue);
}
}
catch (Exception dom) {
System.out.println("getFoldersInfo Err" + dom.toString());
}
return dataList;
}
//解析Reports.xml
public ArrayList getReportsInfo(String path) {
dataList = new ArrayList();
Report dataValue = null;
try {
SAXBuilder builder = new SAXBuilder(false);
Document read_doc = builder.build(new FileInputStream(path));
Element root = read_doc.getRootElement();
List Reports = root.getChildren("Report");
for (int i = 0; i < Reports.size(); i++) {
Element e = (Element) Reports.get(i);
dataValue = new Report();
dataValue.setItemId(e.getAttributeValue("ItemId"));
dataValue.setVariant(e.getAttributeValue("Variant"));
dataValue.setType(e.getAttributeValue("Type"));
dataList.add(dataValue);
}
}
catch (Exception dom) {
System.out.println("getReportsInfo Err" + dom.toString());
}
return dataList;
}
public static void main(String[] args){
XmlConfig xmlconfig = new XmlConfig();
File f = new File("");
ArrayList list = new ArrayList();
list = xmlconfig.getFoldersInfo(f.getAbsolutePath()+f.separator+"MultiReport"+f.separator+"config"+f.separator+"Folders.xml");
}
}
我用XmlConfig.java文件中的main方法测试,能得到争取得解析结果 .
如:
88
文件夹一
8.0.0.
1.0.0.
5
89
文件夹二
20.0.0.
8.0.0.
5
但是当我在createreport.jsp里面调用执行
XmlConfig xConfig = new XmlConfig();
时程序就已经报错误.
错误描述如下:
D:\JBuilderX\jdk1.4\bin\javaw -classpath "D:\JBuilderX\thirdparty\jakarta-tomcat-4.0.6-LE-jdk14\bin\bootstrap.jar;D:\JBuilderX\jdk1.4\lib\tools.jar" -Dcatalina.home="D:/JBuilderX/thirdparty/jakarta-tomcat-4.0.6-LE-jdk14" org.apache.catalina.startup.Bootstrap -config E:\work\BatchPrint\MultiReport\Tomcat\conf\server8083.xml start
HttpConnector Opening server socket on all host IP addresses
Starting service Tomcat-Standalone
Apache Tomcat/4.0.6
WebappLoader[/MultiReport]: Deploying class repositories to work directory E:\work\BatchPrint\MultiReport\Tomcat\work\MultiReport
WebappLoader[/MultiReport]: Deploy JAR /WEB-INF/lib/activation.jar to E:\work\BatchPrint\MultiReport\MultiReport\WEB-INF\lib\activation.jar
WebappLoader[/MultiReport]: Deploy JAR /WEB-INF/lib/axis-ant.jar to E:\work\BatchPrint\MultiReport\MultiReport\WEB-INF\lib\axis-ant.jar
WebappLoader[/MultiReport]: Deploy JAR /WEB-INF/lib/axis.jar to E:\work\BatchPrint\MultiReport\MultiReport\WEB-INF\lib\axis.jar
WebappLoader[/MultiReport]: Deploy JAR /WEB-INF/lib/classes12.jar to E:\work\BatchPrint\MultiReport\MultiReport\WEB-INF\lib\classes12.jar
WebappLoader[/MultiReport]: Deploy JAR /WEB-INF/lib/commons-discovery.jar to E:\work\BatchPrint\MultiReport\MultiReport\WEB-INF\lib\commons-discovery.jar
WebappLoader[/MultiReport]: Deploy JAR /WEB-INF/lib/commons-logging.jar to E:\work\BatchPrint\MultiReport\MultiReport\WEB-INF\lib\commons-logging.jar
WebappLoader[/MultiReport]: Deploy JAR /WEB-INF/lib/jaxrpc.jar to E:\work\BatchPrint\MultiReport\MultiReport\WEB-INF\lib\jaxrpc.jar
WebappLoader[/MultiReport]: Deploy JAR /WEB-INF/lib/junit.jar to E:\work\BatchPrint\MultiReport\MultiReport\WEB-INF\lib\junit.jar
WebappLoader[/MultiReport]: Deploy JAR /WEB-INF/lib/log4j-1.2.8.jar to E:\work\BatchPrint\MultiReport\MultiReport\WEB-INF\lib\log4j-1.2.8.jar
WebappLoader[/MultiReport]: Deploy JAR /WEB-INF/lib/mail.jar to E:\work\BatchPrint\MultiReport\MultiReport\WEB-INF\lib\mail.jar
WebappLoader[/MultiReport]: Deploy JAR /WEB-INF/lib/saaj.jar to E:\work\BatchPrint\MultiReport\MultiReport\WEB-INF\lib\saaj.jar
WebappLoader[/MultiReport]: Deploy JAR /WEB-INF/lib/unittest.jar to E:\work\BatchPrint\MultiReport\MultiReport\WEB-INF\lib\unittest.jar
WebappLoader[/MultiReport]: Deploy JAR /WEB-INF/lib/wsdl4j.jar to E:\work\BatchPrint\MultiReport\MultiReport\WEB-INF\lib\wsdl4j.jar
WebappLoader[/MultiReport]: Reloading checks are enabled for this Context
StandardManager[/MultiReport]: Seeding random number generator class java.security.SecureRandom
StandardManager[/MultiReport]: Seeding of random number generator has been completed
ContextConfig[/MultiReport]: Added certificates -> request attribute Valve
StandardWrapper[/MultiReport:default]: Loading container servlet default
StandardWrapper[/MultiReport:invoker]: Loading container servlet invoker
HttpConnector[8083] Starting background thread
eid:3.
StandardWrapperValve[debugjsp]: Servlet.service() for servlet debugjsp threw exception
javax.servlet.ServletException: org/jdom/input/SAXBuilder
javax.servlet.ServletException: org/jdom/input/SAXBuilder
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:471)
at org.apache.jsp.createreport$jsp._jspService(createreport$jsp.java:400)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:201)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)
at java.lang.Thread.run(Thread.java:534)
在 main函数里面执行都可以返回正确得结果.现在怎么只是实例化XmlConfig类就报错误呢....
网上看到说时jdom的版本问题.我也在webspere的安装目录下面找到了103k的jdom包替换了原来143K的jdom安装包.现在问题仍然存在 ..
请看下,分析下..!
小弟很急..
谢谢..