• Post Reply Bookmark Topic Watch Topic
  • New Topic

directory path

 
gaurav chhabra
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to get the path of of directory through this servlet --:::


String path = req.getPathInfo();
String path1 = req.getPathTranslated();
out.println("path ->>>> "+path);
out.println("path1 ->>>> "+path1);

but in the answer itis giving the NULL in front of both the path.
please help me out.
thank you
gaurav
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Both the methods yo have specified does not return the ditectory pathe.

The getPathInfo() Returns any extra path information associated with the URL the client sent when it made this request. The extra path information follows the servlet path but precedes the query string and will start with a "/" character. This method returns null if there was no extra path information.
Same as the value of the CGI variable PATH_INFO.

The getPathTranslated() method returns any extra path information after the servlet name but before the query string, and translates it to a real path. Same as the value of the CGI variable PATH_TRANSLATED. If the URL does not have any extra path information, this method returns null or the servlet container cannot translate the virtual path to a real path for any reason (such as when the web application is executed from an archive). The web container does not decode this string.

The following methods may useful for what you are trying :
ServletRequest.getRequestURI()
ServletRequest.getRequestURL()
ServletRequest.getServletPath()
and
ServletContext.getRealPath(String)

Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!