Something like the following will work. The important stuff follows "try".
public final class ResourceAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String file = request.getParameter("file"); String ext = file.substring(file.lastIndexOf('.') + 1); String type = null; String path = null; if ("gif".equals(ext)) { type = "image/gif"; path = path("gif"); } else if ("jpg".equals(ext)) { type = "image/jpeg"; path = path("jpeg"); } else if ("css".equals(ext)) { type = "text/css"; path = path("css"); } else if ("flash".equals(ext)) { type = "application/x-shockwave-flash"; path = path("flash"); } else if ("text".equals(ext)) { type = "text/plain"; path = path("text"); } else if ("js".equals(ext)) { type = "text/javascript"; path = path("js"); } else if ("png".equals(ext)) { type = "image/png"; path = path("png"); } else if ("html".equals(ext)) { type = "text/html"; path = path("html"); } else if ("applet".equals(ext)) { type = "application/x-java-applet"; path = applet(); } else if ("bmp".equals(ext)) { type = "image/bmp"; path = path("bmp"); } else if ("tif".equals(ext)) { type = "image/tiff"; path = path("tiff"); } else if ("tiff".equals(ext)) { type = "image/tiff"; path = path("tiff"); } String fileName = Classpath.WEB_INF + path + file; response.setContentType(type); /* E.g. cache = "post-check=120,pre-check=240", = "max-age=86400,private" post-checks are the time after the initial cache at which you have an immediate view without any update. The time from the post to the pre-check is the time whem you get an immediate view but an update. The time after the pre-check time is when you get an update prior to a view. Cf. http://msdn.microsoft.com/workshop/author/perf/perftips.asp#Use_Cache-Control_Extensions */<http://msdn.microsoft.com/workshop/author/perf/perftips.asp#Use_Cache-Control_Extensions*/> String cache = request.getParameter("cache"); /* HTTP 1.1: Numbers are seconds for cache. */ String pragma = request.getParameter("pragma"); /* HTTP 1.0: Numbers are seconds for pragma. */ String expires = request.getParameter("expires");/* HTTP 1.0: Numbers are minutes for expires. */ response.setHeader("Cache-Control", ((cache == null) ? "no-check" : cache)); response.setHeader("Pragma", ((pragma == null) ? "no-check" : pragma)); response.setHeader("Expires", ((expires == null) ? "1440" : expires)); response.addHeader("Content-Disposition",("filename=" + fileName)); try { FileInputStream fis = new FileInputStream(fileName); BufferedInputStream bis = new BufferedInputStream(fis); byte[] bytes = new byte[bis.available()]; OutputStream os = response.getOutputStream(); bis.read(bytes); os.write(bytes); os.flush(); os.close(); os = null; fis.close(); fis = null; bis.close(); bis = null; } catch (IOException ioe) { // YOU DO } return null; } On 12/19/05, Reza Ghaffaripour <[EMAIL PROTECTED]> wrote: > > Hi > i want to show an image in my jsp page. i DON'T want to user the image's > address (on the server's hard disk) and i want to get it directly from db > and set it to the form or something.... > > i also don't want to user ServletOutputStream outStream = > response.getOutputStream(); because it opens the image in a new page or it > wants to download it. > > is there a way to send the image directly to src attribute of the img tag > ? > > > > -- > Reza Ghaffaripour > www.rezaghp.com > > -- "You can lead a horse to water but you cannot make it float on its back." ~Dakota Jack~