Solved

Relative path when uploading image to directory.

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
We have come a long way with backup and data protection — from backing up to floppies, external drives, CDs, Blu-ray, flash drives, SSD drives, and now to the cloud.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

15 Experts available now in Live!

Get 1:1 Help Now