http://zhidao.baidu.com/question/408005631.html
getrealpath()
http://stackoverflow.com/questions/11398513/eclipse-problems-with-getrealpath
disable server location
问题:
使用getServletContext().getRealPath("/")获取地址得到\eclipseworkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps,而不是对应项目目录
分析:
该目录为eclipse中发布工程的临时目录。
解决:
Click on > Servers Tab. Right Click on Servlet container (Tomcat 7 in your case) and Open (F3 is shortcut for eclipse).
Specify the server path (i.e. catalina.base) and deploy path.
You can specify the deploy location here.
如果,修改项为灰色disable。则先进行以下步骤:
- Right click on my tomcat server in "Servers" view, select "Properties…"
- In the "General" panel, click on the "Switch Location" button
- The "Location: [workspace metadata]" bit should have been replaced by something else.
- Open (or close and reopen) the Overview screen for the server.
附:
getRealPath
String getRealPath(String path)
-
Returns a
Stringcontaining the real path for a given virtual path. For example, the path "/index.html" returns the absolute file path on the server's filesystem would be served by a request for "http://host/contextPath/index.html", where contextPath is the context path of this ServletContext..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. This method returns
nullif the servlet container cannot translate the virtual path to a real path for any reason (such as when the content is being made available from a.wararchive). -
-
Parameters:
-
path- aStringspecifying a virtual path
Returns:
-
a
Stringspecifying the real path, or null if the translation cannot be performed
-

本文将解决使用Eclipse获取项目真实路径时遇到的问题,通过调整服务器配置和路径设置,实现正确获取项目目录。
5060

被折叠的 条评论
为什么被折叠?



