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 Displaying image which is outside my web application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Displaying image which is outside my web application" Watch "Displaying image which is outside my web application" New topic
Author

Displaying image which is outside my web application

Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 757
Is it possible to display image which is outside my webapplication ???

i.e. on my hard drive location D:/test.jsp


Jigar Naik


Sunil Vasudevan
Ranch Hand

Joined: Mar 05, 2007
Posts: 107
Technically possible using java.io. But why would you want to do something like that?

It will remove the portability of your web application.


Sunil.V<br />SCJP2, SCWCD1.4, SCBCD1.3
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 757
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

Joined: Aug 21, 2004
Posts: 367
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


SCJP1.4
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 757
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

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying image which is outside my web application