1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter printWriter = response.getWriter();
printWriter.println("Bundles Location Test<br/>");
final String TESTFILENAME = "test.properties";
final String PATHPREFIX = "file:/";
try {
Enumeration<URL> urls = Thread.currentThread().getContextClassLoader().getResources(TESTFILENAME);
if (urls.hasMoreElements()) {
String pathToProperties = urls.nextElement().toString().replaceFirst(PATHPREFIX, "").replaceFirst(TESTFILENAME, "");
printWriter.println("pathToProperties = "+pathToProperties+"<br/>");
File[] children = new File(pathToProperties).listFiles();
if (children != null) {
for (File child : children) {
if (child.isFile())
printWriter.println("resources : " + child.getName() + "<br/>");
}
} else {
printWriter.println("No resources : children is null, pathToProperties = "+pathToProperties+"<br/>");
}
} else {
printWriter.println("No resources : urls.hasMoreElements<br/>");
}
} catch (IOException e) {
printWriter.println("No resources : IOException<br/>");
}
} |
Partager