struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yoganarasimha G" <yoganarasimh...@mphasis.com>
Subject RE: specifying image source as jpg stream
Date Mon, 03 Nov 2003 04:54:03 GMT
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:craigmcc@apache.org]
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: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message