Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying image which is outside my web application

 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to display image which is outside my webapplication ???

i.e. on my hard drive location D:/test.jsp
 
Sunil Vasudevan
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Technically possible using java.io. But why would you want to do something like that?

It will remove the portability of your web application.
 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well,i have created blogging application... in which user can upload image, and i don't want to store image in database field. what are the other alternative to this ???
 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a user can upload an Image isn't the image uploaded to the server where your webapplication exists?

Most often you use say some upload component ( Apache ) maybe and saves it an directory in your webapplication. To get the image just use /myfolder/myimage.jpg

see this link for upload Jakarta fileupload
 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i'm using apache file upload utility

and following is my code to save the uploaded file and regular form fields



when i say File uploadedFile = new File("/test.jpg"); where will test.jpg get stored ???
[ March 21, 2007: Message edited by: Jigar Naik ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mathias Nilsson:
If a user can upload an Image isn't the image uploaded to the server where your webapplication exists?

Most often you use say some upload component ( Apache ) maybe and saves it an directory in your webapplication. To get the image just use /myfolder/myimage.jpg

see this link for upload Jakarta fileupload


Web applications aren't always deployed as expanded file system.
They can be deployed from packed war files. When deployed this way, it isn't possible to upload files to a location within the application's directory structure.

Also, even when run from a file system, many people do not grant write permissions to the web app directories for security reasons.

Jigar,
It is not difficult to write a servlet that streams binary file from the server to the client. I have an example app that does this.
http://simple.souther.us Look for SimpleStream.
In my app, I'm using context.getResourceAsStream to read the file.
In your case, you'll want to use java.io.FileReader becuase the file is not under the web app's directory structure.
I'm sure it wouldn't be difficult to stream the images straight from the database but I don't know what JDBC methods to use off the top of my head.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic