GWT - RPC - 获取servlet的绝对路径来制作目录 [英] GWT - RPC - get servlet absolute path to make dir
问题描述
我尝试使用RemoteServiceServlet读取文件,但是这个文件是
absolute_servlet_path / myPackage /
但是问题是...
代码就像
ServletContext servletContext = this.getServletContext();
String pathContext = servletContext.getRealPath();
...不是C:/ ...,但所以我的问题是我怎样才能使用java。所以我的问题是如何使用java。 io.File与RemoteServiceServlet?
好的...我不得不继续挖掘...
我仍然在寻找一种servlet相对路径的方式,但绝对是一种;现在我再次尝试使用上下文,但这次我修改了我的代码在这个方向...
$ b $ pre $ ServletContext servletContext = this .getServletContext();
String pathContext = servletContext.getRealPath(/ WEB-INF /);
...它对我的Tomcat有用:)
我希望能节省一天
谢谢
I tried to read a file with my "RemoteServiceServlet" but the thing is
- I want to create a dir which path is related to servlet like
absolute_servlet_path/myPackage/
But the problem is...
code like
ServletContext servletContext = this.getServletContext();
String pathContext = servletContext.getRealPath("");
... gives not "C:/..." but "/" only so the code cannot be used with java.io.File object.
So my question is how can I use java.io.File with RemoteServiceServlet ?
OK... I had to keep digging...
Still I was looking for a way of servlet relative path but an absolute one; and now again I tried to use the context but this time I modified my code in this direction...
ServletContext servletContext = this.getServletContext();
String pathContext = servletContext.getRealPath("/WEB-INF/");
... and it worked for my Tomcat :)
I hope it saves one's day
Thanks
这篇关于GWT - RPC - 获取servlet的绝对路径来制作目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!