Dang, Kishore, you are relentless! I like that! You have the option of setting each tag with the value you want for these and programming them in, if you like.
<snip> On Sat, 29 Jan 2005 14:40:26 -0600, Kishore Senji <[EMAIL PROTECTED]> wrote: > > response.setContentType(type); > > response.setHeader("Cache-Control", ""); > > response.setHeader("Pragma", ""); > > response.setHeader("Expires", ""); > > response.addHeader("Content-Disposition","filename=" + name); > > With the above headers, is caching turned on or off. Cache-Control is > set to empty string. If the browsers intrepret this as "no-cache" then > fetching the same image, js or a css file (through the resource > action) over and again might a performance drawback as apposed to > getting those files only once (which is what I guess most browsers do, > cache the images, js, css with static links to resources). Isn't it? </snip> Here is something you could do, for example. 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(); } String fileName = "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 */ 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)); 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(); } catch (IOException ioe) { StdOut.log(SiteConstant.ERROR_LOG,"ResourceAction: problem file is: " + fileName + "\n" + StackTrace.trace(ioe) + "\n" + ioe.getMessage()); } return null; } private String path(String fileType) { return "resource" + File.separator + "content_type" + File.separator + fileType + File.separator; } private String applet() { return "classes" + File.separator + "com" + File.separator + "crackwillow" + File.separator + "applet"; } } ///;-) Jack -- "You can lead a horse to water but you cannot make it float on its back." ~Dakota Jack~ "You can't wake a person who is pretending to be asleep." ~Native Proverb~ "Each man is good in His sight. It is not necessary for eagles to be crows. We are poor . . . but we are free." ~Hunkesni (Sitting Bull), Hunkpapa Sioux~ "This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation." --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]