2008年12月5日

JSP 或是 HttpServlet 中取得資源檔


<%
// HttpServlet 中取得 /WEB-INF/web.xml
// URL url = getServletContext().getResource("/WEB-INF/web.xml");
// JSP 中取得 /WEB-INF/web.xml
URL url = session.getServletContext().getResource("/WEB-INF/web.xml");
InputStream inputStream = url.openStream();
try {
// read from inputStream
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
String line = br.readLine();
while(line != null) {
out.println(line.replaceAll("<","&lt;").replaceAll(">","&gt;"));
line = br.readLine();
}
} finally {
inputStream.close();
}
%>

沒有留言:

網誌存檔