{"id":2466,"date":"2013-12-05T19:12:22","date_gmt":"2013-12-05T10:12:22","guid":{"rendered":"https:\/\/www.united-bears.co.jp\/blog\/?p=2466"},"modified":"2013-12-05T19:12:22","modified_gmt":"2013-12-05T10:12:22","slug":"servletcontext-getrealpath-%e3%81%ae%e5%bc%95%e6%95%b0%e3%82%92%e6%a4%9c%e8%a8%bc%e3%81%99%e3%82%8b%e5%bf%85%e8%a6%81%e3%81%8c%e3%81%82%e3%82%8b%e3%81%8b","status":"publish","type":"post","link":"https:\/\/www.united-bears.co.jp\/blog\/archives\/2466","title":{"rendered":"ServletContext.getRealPath \u306e\u5f15\u6570\u3092\u691c\u8a3c\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u304b"},"content":{"rendered":"<p>Servlet \u3067\u4eee\u60f3\u30d1\u30b9\u304b\u3089\u30d5\u30a1\u30a4\u30eb\u30b7\u30b9\u30c6\u30e0\u4e0a\u306e\u7d76\u5bfe\u30d1\u30b9\u3092\u5f97\u308b\u3068\u304d\u306f\u3001<a href=\"http:\/\/docs.oracle.com\/javaee\/6\/api\/javax\/servlet\/ServletContext.html#getRealPath(java.lang.String)\" target=\"_blank\">ServletContext.getRealPath(String path)<\/a>\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046\u3002\u30e1\u30bd\u30c3\u30c9\u306e\u8aac\u660e\u3092\u8aad\u3080\u3068\u4eee\u60f3\u30d1\u30b9\u3092\u5b9f\u969b\u306e\u30d1\u30b9\u306b\u5909\u63db\u3067\u304d\u306a\u304b\u3063\u305f\u5834\u5408\u306b\u306f null \u3092\u8fd4\u3059\u3088\u3046\u3060\u3057\u3001Servlet \u304c\u7ba1\u7406\u3057\u3066\u3044\u308b\u7bc4\u56f2\u3067\u3057\u304b\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u3081\u306a\u3044\u3088\u3046\u306b\u601d\u3048\u308b\u3002\u4ee5\u4e0b\u306b\u3001\u30e1\u30bd\u30c3\u30c9\u306e\u8aac\u660e\u3092\u5f15\u7528\u3059\u308b\u3002<\/p>\n<blockquote><p>\nGets the <i>real<\/i> path corresponding to the given <i>virtual<\/i> path.<\/p>\n<p>For example, if <tt>path<\/tt> is equal to <tt>\/index.html<\/tt>, this method will return the absolute file path on the server&#8217;s filesystem to which a request of the form <tt>http:\/\/&lt;host&gt;:&lt;port&gt;\/&lt;contextPath&gt;\/index.html<\/tt> would be mapped, where <tt>&lt;contextPath&gt;<\/tt> corresponds to the context path of this ServletContext.<\/p>\n<p>The real path returned will be in a form appropriate to the computer and operating system on which the servlet container is running, including the proper path separators.<\/p>\n<p>Resources inside the <tt>\/META-INF\/resources<\/tt> directories of JAR files bundled in the application&#8217;s <tt>\/WEB-INF\/lib<\/tt> directory must be considered only if the container has unpacked them from their containing JAR file, in which case the path to the unpacked location must be returned.<\/p>\n<p>This method returns <code>null<\/code> if the servlet container is unable to translate the given <i>virtual<\/i> path to a <i>real<\/i> path.\n<\/p><\/blockquote>\n<p>\u3057\u304b\u3057\u3001\u5b9f\u969b\u306b\u306f\u4efb\u610f\u306e\u7269\u7406\u30d1\u30b9\u304c\u623b\u3063\u3066\u304f\u308b\u3053\u3068\u304c\u3042\u308b\u3088\u3046\u3060\u3002Windows + Tomcat 6.0.35 \u306e\u74b0\u5883\u3067\u8a66\u3057\u3066\u307f\u305f\u3002<\/p>\n<pre>\r\nServletContext servletContext; \/\/ \u3069\u3053\u304b\u304b\u3089\u6e21\u3055\u308c\u305f ServletContext\r\nString[] list = new File(servletContext.getRealPath(\"..\/..\/..\/..\/\")).list();\r\nfor(String s: list) {\r\n\tSystem.err.println(s);\r\n}\r\n<\/pre>\n<p>\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3060\u3002<\/p>\n<pre>\r\n$RECYCLE.BIN\r\nworkspace\r\nworkspace-android\r\n<\/pre>\n<p>ServletContext.getRealPath(String path)\u30e1\u30bd\u30c3\u30c9\u306e\u5f15\u6570\u306b\u3001\u30e6\u30fc\u30b6\u30fc\u5165\u529b\u5024\u3092\u4e0e\u3048\u308b\u5834\u5408\u306f\u3001\u5165\u529b\u30c1\u30a7\u30c3\u30af\u3067\u4e88\u671f\u3057\u3066\u3044\u306a\u3044\u6587\u5b57\u304c\u5165\u3063\u3066\u3044\u306a\u3044\u3053\u3068\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Servlet \u3067\u4eee\u60f3\u30d1\u30b9\u304b\u3089\u30d5\u30a1\u30a4\u30eb\u30b7\u30b9\u30c6\u30e0\u4e0a\u306e\u7d76\u5bfe\u30d1\u30b9\u3092\u5f97\u308b\u3068\u304d\u306f\u3001ServletContext.getRealPath(String path)\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046\u3002\u30e1\u30bd\u30c3\u30c9\u306e\u8aac\u660e\u3092\u8aad\u3080\u3068\u4eee\u60f3\u30d1\u30b9\u3092\u5b9f\u969b\u306e\u30d1\u30b9\u306b\u5909\u63db\u3067\u304d\u306a [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,13],"tags":[],"class_list":["post-2466","post","type-post","status-publish","format-standard","hentry","category-java","category-security"],"_links":{"self":[{"href":"https:\/\/www.united-bears.co.jp\/blog\/wp-json\/wp\/v2\/posts\/2466","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.united-bears.co.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.united-bears.co.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.united-bears.co.jp\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.united-bears.co.jp\/blog\/wp-json\/wp\/v2\/comments?post=2466"}],"version-history":[{"count":4,"href":"https:\/\/www.united-bears.co.jp\/blog\/wp-json\/wp\/v2\/posts\/2466\/revisions"}],"predecessor-version":[{"id":2470,"href":"https:\/\/www.united-bears.co.jp\/blog\/wp-json\/wp\/v2\/posts\/2466\/revisions\/2470"}],"wp:attachment":[{"href":"https:\/\/www.united-bears.co.jp\/blog\/wp-json\/wp\/v2\/media?parent=2466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.united-bears.co.jp\/blog\/wp-json\/wp\/v2\/categories?post=2466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.united-bears.co.jp\/blog\/wp-json\/wp\/v2\/tags?post=2466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}