吴裕雄--天生自然轻量级JAVA EE企业应用开发Struts2Sping4Hibernate整合开发学习笔记:Spring_ServletContextResource

<%--
网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
author  yeeku.H.lee kongyeeku@163.com
version  1.0
Copyright (C), 2001-2016, yeeku.H.Lee
This program is protected by copyright laws.
Program Name:
Date: 
--%>

<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<%@ page import="org.springframework.web.context.support.ServletContextResource"%>
<%@ page import="org.dom4j.*,org.dom4j.io.*,java.util.*"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>测试ServletContextResource</title>
</head>
<body>
<h3>测试ServletContextResource</h3>
<%
// 从Web Context下的WEB-INF路径下读取book.xml资源
ServletContextResource src = new ServletContextResource
    (application , "WEB-INF/book.xml");
// 获取该资源的简单信息
System.out.println(src.getFilename());
System.out.println(src.getDescription());
// 创建基于SAX的dom4j解析器
SAXReader reader = new SAXReader();
Document doc = reader.read(src.getFile());
// 获取根元素
Element el = doc.getRootElement();
List l = el.elements();
// 遍历根元素的全部子元素
for (Iterator it = l.iterator();it.hasNext() ; )
{
    // 每个节点都是<书>节点
    Element book = (Element)it.next();
    List ll = book.elements();
    // 遍历<书>节点的全部子节点
    for (Iterator it2 = ll.iterator();it2.hasNext() ; )
    {
        Element eee = (Element)it2.next();
        out.println(eee.getText());
        out.println("<br/>");
    }
}
%>
</body>
</html>
<?xml version="1.0" encoding="GBK"?>
<计算机书籍列表>
    <书>
        <书名>疯狂Java讲义</书名>
        <作者>李刚</作者>
    </书>
    <书>
        <书名>轻量级Java EE企业应用实战</书名>
        <作者>李刚</作者>
    </书>
</计算机书籍列表>
<?xml version="1.0" encoding="GBK"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
    http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">

</web-app>
原文地址:https://www.cnblogs.com/tszr/p/12372282.html