Solved

Relative path when uploading image to directory.

Posted on 2002-03-31
4
414 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
When we talk about DevOps toolchains, I sometimes wonder how many people really get what we’re talking about. I don’t know if it’s just semantics or tone or something else, but sometimes I think it just sounds like buzzword sausage. So it’s always …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

895 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now