WEB-INF
폴더의 리소스에 액세스하려면 응용 프로그램 (jsp - servlet) 내에서 /WEB-INF/test.xml
을 사용하면됩니다.
<!%@ taglib uri="/WEB-INF/tiles-jsp.tld" prefix="tiles" %>
웹 사용자가 사용할 수 있도록하려면 직접 액세스 할 수 없습니다. 사용자가 직접 액세스하려면 WEB-INF 폴더 (예 : /WEB-INF/test.xml 파일을 읽고 jsp/servlet에 출력하는 jsp)에서 파일을 노출하는 일종의 인터페이스가 있어야합니다)
UPDATE
는 서블릿의 사용이를 사용하여 파일을 읽으려면 :
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
StringBuffer strContent = new StringBuffer("");
int ch;
PrintWriter out = response.getWriter();
try {
String path = getServletContext().getRealPath("/WEB-INF/newfile.xml");
File file = new File(path);
FileInputStream fin = null;
try {
fin = new FileInputStream(file);
while ((ch = fin.read()) != -1) {
strContent.append((char) ch);
}
fin.close();
} catch (FileNotFoundException e) {
System.out.println("File " + file.getAbsolutePath()
+ " could not found");
} catch (IOException ioe) {
System.out.println("Exception while reading the file" + ioe);
}
System.out.println("File contents :");
System.out.println(strContent);
} finally {
out.close();
}
}
이 WEB-INF
에서 newfile.xml라는 이름의 파일을 읽고 콘솔에 출력 할 내용됩니다.
파일 내용 : 출력은 같을 것이다
< A>
< B> XXXX </B>
</A>
Q : 정확히 "getServletContext()"메소드에 문제가 있습니까? – paulsm4
정적 블록에서로드하고 싶습니다. – Don
duplicate [웹 아카이브의 WEB-INF 디렉토리에서 리소스를로드하는 방법] (http://stackoverflow.com/questions/1108434/howto-load-a-resource-from-web-inf-directory-of-a- 웹 아카이브) – user1406062