RE: specifying image source as jpg stream
Thanks to all. The image is dynamically created by user action and not creating a image file. I implemented an action for the src and working file. Thanks for the help. -Yoga -Original Message- From: Craig R. McClanahan [mailto:[EMAIL PROTECTED] Sent: Tuesday, October 28, 2003 7:47 AM To: Struts Users Mailing List Subject: Re: specifying image source as jpg stream Max Cooper wrote: You may want to write a separate servlet to serve the image data. That allows you to implement getLastModified() and allow proper browser-caching support, which can significantly increase the speed of your pages if the user is likely to view the images more than once. We did this with an Action first and since we had caching turned off, it reloaded the images every time. Switching to a separate servlet where we implemented getLastModified() was perceptably faster. Perhaps Struts should allow Action-implementers to implement some kind of getLastModified() method for this reason. Or at least to turn caching on and off at the Action (or action-mapping) level. getLastModified() is really useful if you have the image data (or document data, etc.) stored in a db. Controlling this stuff at the per-Action level is a nice idea. If you're using an Action to create dynamic output already (such as when you directly stream the binary output and then return null), it's quite easy to do today -- your Action will be able to see the If-Modified-Since header that the browser sends, and then can decide to return a status 304 (NOT MODIFIED) if your current database stuff is not more recent. Something along the lines of this in your Action.execute() method should do the trick: // When was our database data last modified? long dataModifiedDate = ... timestamp when database last modified ... // Have we sent to this user previously? long modifiedSince = request.getDateHeader(If-Modified-Since); if (modifiedSince -1) { // i.e. it was actually specified if (dataModifiedDate = modifiedSince) { response.sendError(HttpServletResponse.SC_NOT_MODIFIED); return (null); } } // Set the timestamp so the browser can send back If-Modified-Since response.setDateHeader(Date, dataModifiedDate); // Now write the actual content type and data response.setContentType(mage/jpg); ServletOutputStream stream = response.getOutputStream(); ... write out the bytes ... // Return null to tell Struts the response is complete return (null); -Max Craig - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
specifying image source as jpg stream
Hi all I'm developing a webpage which uses xml to display organization chart. I'm using SVG to display the chart in IE. If the user doesn't have SVG viewer I'm converting SVG to JPG using BATIK. At present I'm creating a image file in a temp folder and then displaying, but i want to avoid this and directly give image stream as the source for html:img tag. Can anyone help me how to do this using struts??? regards Yoga - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: specifying image source as jpg stream
Create an Action whose execute method writes the image data directly to the response's output stream and then returns null (you could also use a servlet or filter). Quoting Yoganarasimha G [EMAIL PROTECTED]: Hi all I'm developing a webpage which uses xml to display organization chart. I'm using SVG to display the chart in IE. If the user doesn't have SVG viewer I'm converting SVG to JPG using BATIK. At present I'm creating a image file in a temp folder and then displaying, but i want to avoid this and directly give image stream as the source for html:img tag. Can anyone help me how to do this using struts??? regards Yoga -- Kris Schneider mailto:[EMAIL PROTECTED] D.O.Tech http://www.dotech.com/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: specifying image source as jpg stream
Kris Schneider wrote: Create an Action whose execute method writes the image data directly to the response's output stream and then returns null (you could also use a servlet or filter). Don't forget that, in HTML images are retrieved (by the client) in *separate* requests. You can't intermix the text/html output of your JSP page and the image/jpg binary content of the image on a single response. What you'd want to do, then is create an Action (as described above) that writes the image data directly, and then arrange that your html:img tag references this Action's URL. Craig Quoting Yoganarasimha G [EMAIL PROTECTED]: Hi all I'm developing a webpage which uses xml to display organization chart. I'm using SVG to display the chart in IE. If the user doesn't have SVG viewer I'm converting SVG to JPG using BATIK. At present I'm creating a image file in a temp folder and then displaying, but i want to avoid this and directly give image stream as the source for html:img tag. Can anyone help me how to do this using struts??? regards Yoga - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: specifying image source as jpg stream
You may want to write a separate servlet to serve the image data. That allows you to implement getLastModified() and allow proper browser-caching support, which can significantly increase the speed of your pages if the user is likely to view the images more than once. We did this with an Action first and since we had caching turned off, it reloaded the images every time. Switching to a separate servlet where we implemented getLastModified() was perceptably faster. Perhaps Struts should allow Action-implementers to implement some kind of getLastModified() method for this reason. Or at least to turn caching on and off at the Action (or action-mapping) level. getLastModified() is really useful if you have the image data (or document data, etc.) stored in a db. -Max - Original Message - From: Craig R. McClanahan [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Sent: Monday, October 27, 2003 9:17 AM Subject: Re: specifying image source as jpg stream Kris Schneider wrote: Create an Action whose execute method writes the image data directly to the response's output stream and then returns null (you could also use a servlet or filter). Don't forget that, in HTML images are retrieved (by the client) in *separate* requests. You can't intermix the text/html output of your JSP page and the image/jpg binary content of the image on a single response. What you'd want to do, then is create an Action (as described above) that writes the image data directly, and then arrange that your html:img tag references this Action's URL. Craig Quoting Yoganarasimha G [EMAIL PROTECTED]: Hi all I'm developing a webpage which uses xml to display organization chart. I'm using SVG to display the chart in IE. If the user doesn't have SVG viewer I'm converting SVG to JPG using BATIK. At present I'm creating a image file in a temp folder and then displaying, but i want to avoid this and directly give image stream as the source for html:img tag. Can anyone help me how to do this using struts??? regards Yoga - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: specifying image source as jpg stream
Max Cooper wrote: You may want to write a separate servlet to serve the image data. That allows you to implement getLastModified() and allow proper browser-caching support, which can significantly increase the speed of your pages if the user is likely to view the images more than once. We did this with an Action first and since we had caching turned off, it reloaded the images every time. Switching to a separate servlet where we implemented getLastModified() was perceptably faster. Perhaps Struts should allow Action-implementers to implement some kind of getLastModified() method for this reason. Or at least to turn caching on and off at the Action (or action-mapping) level. getLastModified() is really useful if you have the image data (or document data, etc.) stored in a db. Controlling this stuff at the per-Action level is a nice idea. If you're using an Action to create dynamic output already (such as when you directly stream the binary output and then return null), it's quite easy to do today -- your Action will be able to see the If-Modified-Since header that the browser sends, and then can decide to return a status 304 (NOT MODIFIED) if your current database stuff is not more recent. Something along the lines of this in your Action.execute() method should do the trick: // When was our database data last modified? long dataModifiedDate = ... timestamp when database last modified ... // Have we sent to this user previously? long modifiedSince = request.getDateHeader(If-Modified-Since); if (modifiedSince -1) { // i.e. it was actually specified if (dataModifiedDate = modifiedSince) { response.sendError(HttpServletResponse.SC_NOT_MODIFIED); return (null); } } // Set the timestamp so the browser can send back If-Modified-Since response.setDateHeader(Date, dataModifiedDate); // Now write the actual content type and data response.setContentType(mage/jpg); ServletOutputStream stream = response.getOutputStream(); ... write out the bytes ... // Return null to tell Struts the response is complete return (null); -Max Craig - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]