user592704
user592704

Reputation: 3704

GWT - RPC - get servlet absolute path to make dir

I tried to read a file with my "RemoteServiceServlet" but the thing is

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 ?

Upvotes: 5

Views: 3051

Answers (2)

user592704
user592704

Reputation: 3704

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

Upvotes: 3

Strelok
Strelok

Reputation: 51461

I think you misunderstand how servlets work. A "servlet" is just a class configured via the web.xml file to process requests on a given path at a URL. It's in now way related to the file system at all.

Why would you want to create a folder relative to your servlet's URL? What are you trying to accomplish?

Upvotes: 1

Related Questions