Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Specify path while uploading files using jsp?

 
rohan chakravarthy
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20958
31
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20958
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic