Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Servlets and the fly likes using servlet to generate png image file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "using servlet to generate png image file " Watch "using servlet to generate png image file " New topic

using servlet to generate png image file

Alan Yap
Ranch Hand

Joined: Feb 24, 2006
Posts: 32
As the title suggest, could anyone give me hints and pointers to get me started?

I've tried yahoo and google search with no concrete tutorial/examples in sight.
[ August 29, 2006: Message edited by: Alan Yap ]

When I'm not coding.. I do THIS
Ali Hussain
Ranch Hand

Joined: Jun 19, 2005
Posts: 211
This link might be useful for you: Generating images with JSP/Servlet

- SCEA, SCJD, SCBCD, SCWCD, SCMAD, SCJP, ICAD (WebSphere), Lotus Principal CLP, Lotus CLP, Lotus CLS
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1323

Welcome to JavaRanch Alan Yap

There some links to generate image file with example of source code
it might be helpful for you..

Create dynamic images in Java servlets
Using Servlets to Generate JPEG Images
Creating a Buffered Image from an image
Images - BufferedImage
[ August 29, 2006: Message edited by: Saif Uddin ]

[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Alan Yap
Ranch Hand

Joined: Feb 24, 2006
Posts: 32
thanks guys,

going through those links now.

Found some tutorials earlier on this too, using JSP. Tweaked their code a bit and it works in my machine (Resin 2.1 + J2SDK1.4.0).

But when uploaded into my hosting server to be tested, this exception pops up: access denied (
/tut/z.png delete)
at java.lang.SecurityManager.checkPermission(
at java.lang.SecurityManager.checkDelete(
at javax.imageio.ImageIO.write(
at _pngwrite__jsp._jspService(/tut/pngwrite.jsp:19)
at com.caucho.jsp.JavaPage.service(
at com.caucho.jsp.Page.subservice(
at com.caucho.server.http.FilterChainPage.doFilter(
at com.caucho.server.http.Invocation.service(
at com.caucho.server.http.CacheInvocation.service(
at com.caucho.server.http.RunnerRequest.handleRequest(
at com.caucho.server.http.RunnerRequest.handleConnection(

While waiting for the hosting to get back to me on this issue, I was wondering if this is caused by the restriction imposed by the hosting, or should I tweak my code a bit more to fix it ?
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
In a hosted environment you won't have access to the complete file system, just to your personal space or web app directory. That most likely does not include a top-level directory called "/tut". You'll need to save the image in a directory that's part of your environment there.
I agree. Here's the link:
subject: using servlet to generate png image file
jQuery in Action, 3rd edition