Solved

Relative path when uploading image to directory.

Posted on 2002-03-31
4
420 Views
Last Modified: 2008-01-09
How do I specify the relative path of the directory where I use the MultipartRequest class from "http://www.servlets.com/cos/javadoc/com/oreilly/servlet/MultipartRequest.html" 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
0
Comment
Question by:Gin_a
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 19

Expert Comment

by:cheekycj
ID: 6910301
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?

CJ
0
 
LVL 6

Accepted Solution

by:
kotan earned 50 total points
ID: 6911561
You can't specify the relative path in MultipartRequest class.

Here is part of the code of MultipartRequest.java

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);
0
 

Author Comment

by:Gin_a
ID: 6911586
what you mean by the application?
0
 
LVL 6

Expert Comment

by:kotan
ID: 6911599
application is predefined variable in jsp which is the ServletContext as obtained via getServletConfig().getContext()
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A big percent of today’s marketing activity is performed through the online environment. The marketing strategies that have existed a decade ago no longer relate to what’s happening today. We’re currently facing a revolutionary era, called the digit…
Invest in your employees with these five simple steps to improve employee engagement and retention.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question