有一处错误谁帮忙改下吧
程序代码:
<%@ page contentType="text/html;charset=gb2312" %> <%@ page language="java" %> <%@ page import="*" %> <%@ page import="java.util.*" %> <%@ page import="org.w3c.dom.*"%> <%@ page import="javax.xml.parsers.*"%> <%@ page import="javax.xml.transform.*" %> <%@ page import="javax.xml.transform.stream.*"%> <%@ page import="javax.xml.transform.dom.*"%> <%@ page import="javax.xml.transform.OutputKeys.*"%> <HTML> <HEAD><TITLE>删除已受理订单</TITLE></HEAD> <BODY> <% int i=0; //建立一个解析器工厂,以获得一个具体的解析器对象: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); //使用newDocumentBuilder()方法可以获得一个DocumentBuilder对象 DocumentBuilder db = dbf.newDocumentBuilder(); //打开现有的xml文档 Document doc = db.parse(getServletConfig().getServletContext().getRealPath ("book0.xml")); try{ Element root = doc.getDocumentElement();//根节点 for(i=0;i<root.getChildNodes();i++) root.removeChild(root.getElemntsByTagName("book").item(i)); String fileName = "book0.xml"; String outFile = getServletConfig().getServletContext().getRealPath(fileName); //定义转换器 Transformer tf = javax.xml.transform.TransformerFactory.newInstance().newTransformer(); //防止汉字乱码 tf.setOutputProperty(OutputKeys.ENCODING,"gb2312"); //设定XSLT引擎在输出XML文档时,是否自动添加额外的空格 tf.setOutputProperty(OutputKeys.INDENT,"yes"); //将XML文档树doc转换输出到文件 tf.transform(new DOMSource(doc),new StreamResult(outFile)); %> 已受理订单已经删除<br> <a href=<%=fileName%>>点击这里打开产生的XML文档<%=fileName%> </a> <% } catch (Exception e) { System.out.println (e.getMessage()); } %> </BODY> </HTML>for(i=0;i<root.getChildNodes();i++)
root.removeChild(root.getElemntsByTagName("book").item(i));
这句错误了
程序代码:
org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 24 in the jsp file: /del_book.jsp The operator < is undefined for the argument type(s) int, NodeList 21: Document doc = db.parse(getServletConfig().getServletContext().getRealPath ("book0.xml")); 22: try{ 23: Element root = doc.getDocumentElement();//根节点 24: for(i=0;i<root.getChildNodes();i++) 25: root.removeChild(root.getElemntsByTagName("book").item(i)); 26: String fileName = "book0.xml"; 27: String outFile = getServletConfig().getServletContext().getRealPath(fileName); An error occurred at line: 25 in the jsp file: /del_book.jsp The method getElemntsByTagName(String) is undefined for the type Element 22: try{ 23: Element root = doc.getDocumentElement();//根节点 24: for(i=0;i<root.getChildNodes();i++) 25: root.removeChild(root.getElemntsByTagName("book").item(i)); 26: String fileName = "book0.xml"; 27: String outFile = getServletConfig().getServletContext().getRealPath(fileName); 28: //定义转换器 Stacktrace: org.apache.(DefaultErrorHandler.java:92) org.apache.(ErrorDispatcher.java:330) org.apache.(JDTCompiler.java:439) org.apache.(Compiler.java:334) org.apache.(Compiler.java:312) org.apache.(Compiler.java:299) org.apache.jasper.(JspCompilationContext.java:589) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)