File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Specify path while uploading files using jsp? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Specify path while uploading files using jsp?" Watch "Specify path while uploading files using jsp?" New topic
Author

Specify path while uploading files using jsp?

rohan chakravarthy
Greenhorn

Joined: Apr 13, 2012
Posts: 7
So I'm trying to upload files. I use one page "uploadimage" to accept the image and "imageuploaded" to store it. The problem is that the uploaded files get stored in the tomcat bin folder. Is there a way to specify the path where the image should be stored?

Uploadimage:




imageuploaded:

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Of course. Just pick a folder which already exists on the server, or create one if you need to. Then output to a file (with your chosen name) in that folder. Right now you aren't specifying a folder name at all, so by default you're writing to a file in the current working directory of your application server.

Perhaps you were misled by thinking that your question was a question about JSP? But it isn't, it's just a question about Java programming. So just use normal Java programming techniques to write to a file in a specified folder.
rohan chakravarthy
Greenhorn

Joined: Apr 13, 2012
Posts: 7
But how do I specify the path? I just read another forum topic and changed the code accordingly. It still doesn't work:

imageuploaded

rohan chakravarthy
Greenhorn

Joined: Apr 13, 2012
Posts: 7
ok I made a REALLY stupid mistake. Didn't specify the / before the image name. Thanks a lot Paul! Thats twice you've helped me today!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Yes, it's easy to do that sort of thing when you're using string concatenation. And even though you've fixed up that little problem, let me suggest a better way to do it:



Here you don't need to worry about putting in the path separator, and about not putting in two of them, and you don't need to have that nagging feeling in the back of your mind that the path separator on Windows is really a backslash so using a slash is cheating even if it works perfectly well. The code in the File takes care of all those ugly details.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Specify path while uploading files using jsp?
 
Similar Threads
Problem with uploading images
error in uploading zip file
uploading the content of a .csv file in database
problem in uploading a file
upload data and image at the same time