File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Writing to file and dynamic image pages. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Writing to file and dynamic image pages." Watch "Writing to file and dynamic image pages." New topic

Writing to file and dynamic image pages.

Prashanth menon
Ranch Hand

Joined: Feb 20, 2001
Posts: 65
I have used Tomcat. Now I use Tomcat4.0 Winnt version. whenever I create a new file for writting itis created in the system32 directory of winnt. I have not tried giving the full path as I wonder if it works.
In fact it failed when I tested with Jrun3.0 where the file is created in the default dir.
What I want to do is using some Image Api s like JAI,Graphics2D I want to embed an image that is dynamically created into the page, and in the process save it.Here I would like to generate reports in the form of barcharts and pie charts.
Now if I create a jpeg image and save it,it goes to the system32 directory.We cannot thus give the HREF to the image in the response.
I was able to send an image by seting the content type. But I want also HTML matter to go with it.
Ram Dhan Yadav K
Ranch Hand

Joined: Aug 13, 2001
Posts: 321
Hi Prasanth,
Just awild guess, while sending image to the page, you must writing the bytes to the stream right? In the process why don't you write the html output also to the stream?

Ram Dhan Yadav (SCJP, SCWCD, SCJA-I, IBM EC(483))
"We are what we repeatedly do. Excellence, then, is not an act, but a habit."
Prashanth menon
Ranch Hand

Joined: Feb 20, 2001
Posts: 65
Images are sent as stream. I use JpegEncoder. But how does the browser recognize the mime type. Naturally I specify the content-type. But that is the header part of what I send. Once an Image/jpeg content is written to output how can an html content be sent.
The earlier problem has a solution something like this, may be
in a jsp page or servlet
out.println("<Img src=\"http://myserver/servlet/ ImageProcessServlet\">");
in this case the contentype set is text/html
At the same time in the ImageProcessServlet the contentype returned is Image/jpeg. Hence it works.
What I wanted to know was if it was possible to write to the html documents folder or where http protocol could access I could directly place the tag href="filename". May be it has been eliminated because of security reasons.
But I felt the problem more pushing when I could not save the file uploaded as multipart to the http folder. Take this case.
A client uploads an image at a portal. If the image is in the default folder then I must write another servlet like the one above to read and send it to the servlet requested. This image should be shown to the Client whenever he logs in or anyone checks his profile.
I agree. Here's the link:
subject: Writing to file and dynamic image pages.
It's not a secret anymore!