网格来自XML数据

时间:2012-06-29 04:42:43

标签: java xml

我创建了jsp页面来显示xml数据中的网格。下面我展示了我的jsp(解析jsp

)页面和xml(display.xml)页面。

parsing.jsp

%@ page contentType="text/html"%> 

%@ page import="javax.xml.parsers.DocumentBuilderFactory, 

javax.xml.parsers.DocumentBuilder,org.w3c.dom.*" 

%>  

% 

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 

DocumentBuilder db = dbf.newDocumentBuilder(); 

Document doc = db.parse("http://10.100.133.106:50000/XMII/CM/Glory/Sample/display.xml"); 


NodeList nl= doc.getElementsByTagName("title"); 

NodeList n2= doc.getElementsByTagName("author"); 

NodeList n3= doc.getElementsByTagName("year");  

NodeList n4= doc.getElementsByTagName("price"); 

%>  

html> 

body><center> 

table width="500" border="0" cellspacing="0" cellpadding="0"> 

tr>  

td style="background:#000033;color:#FFFFFF;font-weight:bold;">Title/td> 

td style="background:#000033;color:#FFFFFF;font-weight:bold;">Author/td> 

td style="background:#000033;color:#FFFFFF;font-weight:bold;">Year/td> 

td style="background:#000033;color:#FFFFFF;font-weight:bold;">Price/td> 

/tr> 

tr>  

<% 

for(int i=0;i<3;i++) 

{ 

%> 

<td><%= nl.item(i).getFirstChild().getNodeValue() %></td> 

<td><%= n2.item(i).getFirstChild().getNodeValue() %></td> 

<td><%= n3.item(i).getFirstChild().getNodeValue() %></td> 

<td><%= n4.item(i).getFirstChild().getNodeValue() %></td> 

</tr> 

<%  

} 

%> 
/table> 

/center> 

/body> 

/html>

display.xml

?xml version="1.0" encoding="ISO-8859-1" ?> 

bookstore> 

book category="COOKING"> 

title lang="en">Everyday Italian/title> 

author>Giada De Laurentiis/author>  

year>2005/year> 

price>30.00/price> 

/book> 
book category="CHILDREN"> 

title lang="en">Harry Potter/title> 

author>J K. Rowling/author>  

year>2005/year> 

price>29.99/price> 

/book> 

book category="WEB"> 

title lang="en">Learning XML/title> 

author>Erik T. Ray/author>  

year>2003/year> 

\price>39.95/price> 

\book> 

\/bookstore>

执行时会收到错误报告。

  

错误:&#34;请求处理期间发生了应用程序错误。&#34;

     

故障排除指南   https://sdn.sap.com/irj/sdn/wiki?path=/display/JSTS/Home

     

详细说明:

     

org.xml.sax.SAXParseException:以下文档中的标记   根元素必须格式良好。在   com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:264)   在   com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:292)   在javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:165)
  在   JEE_jsp_CM_Glory_Sample_displayXML_8904750_1340860399234_1340860399922._jspService(JEE_jsp_CM_Glory_Sample_displayXML_8904750_1340860399234_1340860399922.java:51)   在   com.sap.engine.services.servlets_jsp.lib.jspruntime.JspBase.service(JspBase.java:102)   在   com.sap.engine.services.servlets_jsp.server.Invokable.invoke(Invokable.java:140)   在   com.sap.engine.services.servlets_jsp.server.servlet.JSPServlet.service(JSPServlet.java:436)   在   com.sap.engine.services.servlets_jsp.server.servlet.JSPServlet.service(JSPServlet.java:240)   在javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
  在   com.sap.engine.services.servlets_jsp.server.runtime.FilterChainImpl.runServlet(FilterChainImpl.java:162)   在   com.sap.engine.services.servlets_jsp.server.runtime.FilterChainImpl.doFilter(FilterChainImpl.java:81)   在com.sap.xmii.system.SecurityFilter.doFilter(SecurityFilter.java:96)   在   com.sap.engine.services.servlets_jsp.server.runtime.FilterChainImpl.doFilter(FilterChainImpl.java:73)   在com.sap.xmii.system.SecurityFilter.doFilter(SecurityFilter.java:96)   在   com.sap.engine.services.servlets_jsp.server.runtime.FilterChainImpl.doFilter(FilterChainImpl.java:73)   在   com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:461)   在   com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:298)   在   com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:397)   在   com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:386)   在   com.sap.engine.services.servlets_jsp.filters.DSRWebContainerFilter.process(DSRWebContainerFilter.java:48)   在   com.sap.engine.services.httpserver.chain.AbstractChain.process(AbstractChain.java:78)   在   com.sap.engine.services.servlets_jsp.filters.ServletSelector.process(ServletSelector.java:83)   在   com.sap.engine.services.httpserver.chain.AbstractChain.process(AbstractChain.java:78)   在   com.sap.engine.services.servlets_jsp.filters.ApplicationSelector.process(ApplicationSelector.java:243)at   com.sap.engine.services.httpserver.chain.AbstractChain.process(AbstractChain.java:78)   在   com.sap.engine.services.httpserver.filters.WebContainerInvoker.process(WebContainerInvoker.java:78)   在   com.sap.engine.services.httpserver.chain.HostFilter.process(HostFilter.java:9)   在   com.sap.engine.services.httpserver.chain.AbstractChain.process(AbstractChain.java:78)   在   com.sap.engine.services.httpserver.filters.ResponseLogWriter.process(ResponseLogWriter.java:60)   在   com.sap.engine.services.httpserver.chain.HostFilter.process(HostFilter.java:9)   在   com.sap.engine.services.httpserver.chain.AbstractChain.process(AbstractChain.java:78)   在   com.sap.engine.services.httpserver.filters.DefineHostFilter.process(DefineHostFilter.java:27)   在   com.sap.engine.services.httpserver.chain.ServerFilter.process(ServerFilter.java:12)   在   com.sap.engine.services.httpserver.chain.AbstractChain.process(AbstractChain.java:78)   在   com.sap.engine.services.httpserver.filters.MonitoringFilter.process(MonitoringFilter.java:29)   在   com.sap.engine.services.httpserver.chain.ServerFilter.process(ServerFilter.java:12)   在   com.sap.engine.services.httpserver.chain.AbstractChain.process(AbstractChain.java:78)   在   com.sap.engine.services.httpserver.filters.MemoryStatisticFilter.process(MemoryStatisticFilter.java:43)   在   com.sap.engine.services.httpserver.chain.ServerFilter.process(ServerFilter.java:12)   在   com.sap.engine.services.httpserver.chain.AbstractChain.process(AbstractChain.java:78)   在   com.sap.engine.services.httpserver.filters.DSRHttpFilter.process(DSRHttpFilter.java:42)   在   com.sap.engine.services.httpserver.chain.ServerFilter.process(ServerFilter.java:12)   在   com.sap.engine.services.httpserver.chain.AbstractChain.process(AbstractChain.java:78)   在   com.sap.engine.services.httpserver.server.Processor.chainedRequest(Processor.java:428)   在   com.sap.engine.services.httpserver.server.Processor $ FCAProcessorThread.process(Processor.java:247)   在   com.sap.engine.services.httpserver.server.rcm.RequestProcessorThread.run(RequestProcessorThread.java:45)   在   com.sap.engine.core.thread.execution.Executable.run(Executable.java:122)   在   com.sap.engine.core.thread.execution.Executable.run(Executable.java:101)   在   com.sap.engine.core.thread.execution.CentralExecutor $ SingleThread.run(CentralExecutor.java:327)

但是xml数据得到了很好的证实。请解决这个问题

此致

0 个答案:

没有答案