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 / July 2006

Tip: Looking for answers? Try searching our database.

A file writing dilemma....!

Thread view: 
andrew.kitchen@gmail.com - 17 Jul 2006 12:26 GMT
Hi,

I have a webapp that I deploy using a WAR file. This application needs
to write image files to disk when I upload images. These images
currently reside in my webapp, but of course this causes problems when
I want to deploy a new WAR as it throws the images away.

What I believe is the solition is to write the images to a different
context so that they will not be overwritten, rather than write the
images to a database. I don't need to link to these images directly
from my webapp's JSP as I will read the images in so that I can
dynamically create thumbnails and watermark them etc....

I have set-up a new context for the images and my webapp can connect to
it. However I cannot find any code or such that shows examples of how
to write or read files from another context. Can you do this from
within your main webapp, or do you need to invoke a servlet in the
other context to provide file IO?

Any help gratefully received :-)

thanks in advance.
Andrew
Ingo R. Homann - 17 Jul 2006 13:35 GMT
Hi,

I'm not sure, if I understand you correctly, but why do you not want to
store the Image in the database?

BTW: In HttpServlet, there are methods to get the directory of a
webapplication where you could store files.

Ciao,
Ingo
andrew.kitchen@gmail.com - 17 Jul 2006 13:56 GMT
Hi Ingo,

I recon the images are best saved to disk than the database, especially
as I am using a remote shared server. If I were running this on my own
machine I might think differently. It is the backup issue and file
copying that move me towards having a file system solution, as I could
have several thousand images in a year's time.

I'll try and clarify the problem here:

I have a web application context deployed in a WAR file called
context1. This is the main application. I have configured a second
context called context2 which has a docBase outside of context1'.

Within the context1 application I have a Struts enabled JSP with a form
for submitting an image file. This form's corresponding action class,
when complete, will get the file and write it to a directory within
context2 of my chosing. I might have to create a new directory, but the
long and short of it is that it will be written to this context.

In context1's web application there will be another JSP that will
display the image, but via a servlet so that I can overlay watermarking
on the image and create a dynamic thumbnail.

I hope that makes things more clear?

Thanks in advance for your help.
Andrew

> Hi,
>
[quoted text clipped - 6 lines]
> Ciao,
> Ingo
Ingo R. Homann - 17 Jul 2006 14:10 GMT
Hi,

Well, what about a system-parameter in which you specify the directory,
in which the images should be stored?

Ciao,
Ingo
andrew.kitchen@gmail.com - 17 Jul 2006 14:34 GMT
Ingo,

So you recon perhaps just setting a simple system parameter is the best
idea? I was trying to make it as neat as possible, but I suppose my way
is overcomplicating things.

I'll try and just write to a repository directory and see whether that
works.

thanks,
andrew

> Hi,
>
[quoted text clipped - 3 lines]
> Ciao,
> Ingo
andrew.kitchen@gmail.com - 18 Jul 2006 08:00 GMT
Ingo,

> BTW: In HttpServlet, there are methods to get the directory of a
> webapplication where you could store files.

Which methods are these and can you give me an example?

Thanks,
Andrew
Ingo R. Homann - 18 Jul 2006 08:17 GMT
Hi andrew,

>>BTW: In HttpServlet, there are methods to get the directory of a
>>webapplication where you could store files.
>
> Which methods are these and can you give me an example?

RTFM:

out.println(getServletContext().getRealPath(".") + "<br>");

Hth,
Ingo
andrew.kitchen@gmail.com - 18 Jul 2006 14:45 GMT
Ah right - I had used this one already but had used "/" instread of "."

Thanks for that - I had already RTFM - I wasn't being a clown!

Andrew

> Hi andrew,
>
[quoted text clipped - 9 lines]
> Hth,
> Ingo


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.