Solved

Relative path when uploading image to directory.

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

Here's how to start interacting with our community through Post.
Popular third-party chat platforms like Slack, Discord, and Telegram are just a few of the many new productivity applications that are being hijacked by cybercriminals to create command-and-control (C&C) communications infrastructures for their malw…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

707 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