Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2007

Tip: Looking for answers? Try searching our database.

upload and download of images with Tomcat

Thread view: 
Wojtek - 07 Sep 2007 08:46 GMT
Hello,

I try to upload images for futher download (as in a image
gallery) to a folder under web application dir. Everything goes
fine except one thing: the uploaded images are not seen
in the application till next deployment
of the application (Tomcat does not see the images).

Is it possible to make Tomcat see dynamically added
static content? I know that one of the solution is using
web server for serving static resources, but I would
like to find a solution in Tomcat.

 Best regards,

 Wojtek Stanczuk
Manish Pandit - 07 Sep 2007 23:42 GMT
> Hello,
>
[quoted text clipped - 12 lines]
>
>   Wojtek Stanczuk

The webserver solution is the best one IMO, however, if you want a
tomcat based solution, then you'd have to read the uploaded files in
the servlet/action, after persist them on the file system (which I
believe you're doing currently). However, to render them, read them
back from that location and write the output on the response. That
location can be a preference/property for the application.

Something like:

                 byte[] bytes =
FileUtils.readFileToByteArray(your_file_as_java_io_File); //Apache
Commons IO
        response.setHeader("Content-Disposition", "attachment; filename=
\""+name_of_the_file+"\"");
        response.setContentLength(bytes.length);
        response.setContentType(resolve_content_type_based_on_extension);
        response.getOutputStream().write(bytes);
        response.getOutputStream().flush();
        response.getOutputStream().close();

However, I find Apache+PHP much better for this kind of thing :)

-cheers,
Manish


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.