[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Relative path when uploading image to directory.

Posted on 2002-03-31
4
Medium Priority
?
428 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 200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
With so many activities to perform, Exchange administrators are always busy in organizations. If everything, including Exchange Servers, Outlook clients, and Office 365 accounts work without any issues, they can sit and relax. But unfortunately, it…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

656 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