Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    getServletContext().getRealPath( "/" ) does not work on server side

    Hello,

    does somebody knows how to get the context path on server side? I am trying to delete a file in the folder "WebInf/uploads", but I am unable to get the file path.

    getServletContext().getRealPath( "/" ) + "uploads/";

    I used the import "javax.servlet.http.HttpServlet" for the class

    But it does not help.

    Thanks
    Andy

    #2
    ok i finally found a simple way... I have choosen a class wich is located in the server packe and used the following method:

    Code:
    String filePath = DEmail.class.getResource( "/" ).getPath()
    Since all folders in the war directory are the same...I can manipulate the "filePath" as follows:

    Code:
    String filePath = DEmail.class.getResource( "/" ).getPath().replaceFirst( "/", "" ).replace( "WEB-INF/classes/", "/uploads/" ) + "text.txt";
    Et Voila I have the relative path on the server for my file in the upload directory.

    Comment

    Working...
    X