Relative path when uploading image to directory.

How do I specify the relative path of the directory where I use the MultipartRequest class from "" in my jsps.
eg: MultipartRequest mReq = new MultipartRequest(req, direc);

As when I want the direc to be a relative path so that when i put my main folder. I will still be able to store the image in the respective image folder
Who is Participating?
kotanConnect With a Mentor Commented:
You can't specify the relative path in MultipartRequest class.

Here is part of the code of

public MultipartRequest(HttpServletRequest request,
                          String saveDirectory,
                          int maxPostSize) throws IOException {
 // Save the dir
    dir = new File(saveDirectory);

From here, we know that it didn't let us specify relative path.

Anyway, you can use ServletContext.getRealPath() to get full path of the web application.

JSP's eg:

String fullpath = application.getRealPath("/") + direc;
MultipartRequest mReq = new MultipartRequest(req, fullpath);
An option is to use "/", which means the root directory of the application (current web application root as defined in the web.xml) .. maybe you can use that?

Gin_aAuthor Commented:
what you mean by the application?
application is predefined variable in jsp which is the ServletContext as obtained via getServletConfig().getContext()
All Courses

From novice to tech pro — start learning today.