You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Stjepan Brbot <st...@zg.t-com.hr> on 2007/07/01 22:57:13 UTC

Dynamically rendering image - Servlet/Action

Hi,

I have one classic HttpServlet for dynamically rendering an image from given 
(database retrieved) data. Actually this servlet takes data from session 
(previously retrieved from database and put inside session) and renders the 
image. Since this is not Action but classis servlet it is mapped in web.xml 
as '/ImageServlet'. When I have in my html/jsp tag like this one '<img 
src="/ImageServlet">', I get wanted image. That's all fine.

Now, I'd like to avoid using session for this purpose and like to take data 
for ImageServlet from request but I see that request data is not forwarded 
in additional browser's request for image. When I originally request page 
like 'page.jsp?id=1' this 'id=1' is not forwarded in request for image data 
'<img src="/ImageServlet">' from page.jsp! That's why I use session. Is this 
only possibility? Can I use '<html:img src=.../>' or '<html:img action=...>' 
and expect original page request to be forwarded to image request as well?

On the other hand, how to create Struts' Action that could be used for the 
same purpose of rendering image? In classic HttpServlet there are methods 
doPost/doGet which do not return any data (void) but Struts' Action expects 
ActionForward as a return value. What might be the return value in case that 
this Action is used for rendering image and called inside '<img 
src="/ImageAction">' or '<html:img action="/ImageAction"/>'?

SB



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


Re: Dynamically rendering image - Servlet/Action

Posted by Stjepan Brbot <st...@zg.t-com.hr>.
----- Original Message ----- 
From: "Niall Pemberton" <ni...@gmail.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: 2. srpanj 2007 16:49
Subject: Re: Dynamically rendering image - Servlet/Action
>
> There is just such a DownLoad action designed to help with this - you
> just need to return "null" from the Action's execute method, rather
> than an ActionForward:
>
> http://wiki.apache.org/struts/StrutsFileDownload
> http://struts.apache.org/1.3.8/apidocs/org/apache/struts/actions/DownloadAction.html
>
> Niall
>

Thanks Niall,

I'm little bit rusty with Struts specially in case of new Struts versions. I 
started again with Struts after 2 years gap (used to work with v1.0 and 
v1.1) and see that a lot of things changed :-) I will examine this 
StrutsFileDownload Action to see if it can help me. Thanks again.

SB 


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


Re: Dynamically rendering image - Servlet/Action

Posted by Niall Pemberton <ni...@gmail.com>.
On 7/1/07, Stjepan Brbot <st...@zg.t-com.hr> wrote:
> Hi,
>
> I have one classic HttpServlet for dynamically rendering an image from given
> (database retrieved) data. Actually this servlet takes data from session
> (previously retrieved from database and put inside session) and renders the
> image. Since this is not Action but classis servlet it is mapped in web.xml
> as '/ImageServlet'. When I have in my html/jsp tag like this one '<img
> src="/ImageServlet">', I get wanted image. That's all fine.
>
> Now, I'd like to avoid using session for this purpose and like to take data
> for ImageServlet from request but I see that request data is not forwarded
> in additional browser's request for image. When I originally request page
> like 'page.jsp?id=1' this 'id=1' is not forwarded in request for image data
> '<img src="/ImageServlet">' from page.jsp! That's why I use session. Is this
> only possibility? Can I use '<html:img src=.../>' or '<html:img action=...>'
> and expect original page request to be forwarded to image request as well?
>
> On the other hand, how to create Struts' Action that could be used for the
> same purpose of rendering image? In classic HttpServlet there are methods
> doPost/doGet which do not return any data (void) but Struts' Action expects
> ActionForward as a return value. What might be the return value in case that
> this Action is used for rendering image and called inside '<img
> src="/ImageAction">' or '<html:img action="/ImageAction"/>'?

There is just such a DownLoad action designed to help with this - you
just need to return "null" from the Action's execute method, rather
than an ActionForward:

http://wiki.apache.org/struts/StrutsFileDownload
http://struts.apache.org/1.3.8/apidocs/org/apache/struts/actions/DownloadAction.html

Niall

> SB

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


Re: Dynamically rendering image - Servlet/Action

Posted by Stjepan Brbot <st...@zg.t-com.hr>.
Actually I can do that (make database connection from servlet rendering an 
image) but I'd like to avoid that and I'll explain why.

I'm working on one small dashboard. On this dashboard I have one select into 
database for retrieving 10-20 rows, each row data is represented by one 
gauge widget (Graphics2D image rendered by my servlet). So if I'd like to 
show 20 gauge images on one page I can do this by mains:
a) retrieve this one recordset with all 20 records, put this recordset data 
into session (I'd like to use request here) and render 20 images using these 
data from session
b) I can retrieve once this recordset with 20 records, use ID's from 
recordset and forward 20 ID's to my servlet (servlet has to establish 20 
additional connections for rendering each image on page resulting in 21 
connections in total).

This second approach would work but it doesn't look so good to me. Moreover 
when you retrieve data about 20 rows in one pool connection, why not to 
exploit it for rendering images instead of retrieving these same data one by 
one for each image afterwards? That's why I'd like to put recordset data 
into request and send it to jsp page, and page to forward this request 
further to servlet rendering images (in <img src=..>) but this request data 
is not forwarded!


----- Original Message ----- 
From: "Larry Meadors" <lm...@apache.org>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: 2. srpanj 2007 16:59
Subject: Re: Dynamically rendering image - Servlet/Action


> If it's in request scope, I'm assuming it is transient data, so why
> not pass the key to the database row to the servlet?
>
> /ImageServlet?rowKey=123
>
> Or if you want to be more clever, even:
>
> /ImageServlet/123
> /ImageServlet/123/file.png
>
> I've done that before to deal with stupid browsers that seem to want
> to ignore the mime type and insist on fetching a *.do file. Retarded.
>
> anyway, you can read that parameter in your servlet, fetch the data,
> and send it back. Easy. :-)
>
> Larry


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


Re: Dynamically rendering image - Servlet/Action

Posted by Larry Meadors <lm...@apache.org>.
If it's in request scope, I'm assuming it is transient data, so why
not pass the key to the database row to the servlet?

/ImageServlet?rowKey=123

Or if you want to be more clever, even:

/ImageServlet/123
/ImageServlet/123/file.png

I've done that before to deal with stupid browsers that seem to want
to ignore the mime type and insist on fetching a *.do file. Retarded.

anyway, you can read that parameter in your servlet, fetch the data,
and send it back. Easy. :-)

Larry


On 7/1/07, Stjepan Brbot <st...@zg.t-com.hr> wrote:
> Hi,
>
> I have one classic HttpServlet for dynamically rendering an image from given
> (database retrieved) data. Actually this servlet takes data from session
> (previously retrieved from database and put inside session) and renders the
> image. Since this is not Action but classis servlet it is mapped in web.xml
> as '/ImageServlet'. When I have in my html/jsp tag like this one '<img
> src="/ImageServlet">', I get wanted image. That's all fine.
>
> Now, I'd like to avoid using session for this purpose and like to take data
> for ImageServlet from request but I see that request data is not forwarded
> in additional browser's request for image. When I originally request page
> like 'page.jsp?id=1' this 'id=1' is not forwarded in request for image data
> '<img src="/ImageServlet">' from page.jsp! That's why I use session. Is this
> only possibility? Can I use '<html:img src=.../>' or '<html:img action=...>'
> and expect original page request to be forwarded to image request as well?
>
> On the other hand, how to create Struts' Action that could be used for the
> same purpose of rendering image? In classic HttpServlet there are methods
> doPost/doGet which do not return any data (void) but Struts' Action expects
> ActionForward as a return value. What might be the return value in case that
> this Action is used for rendering image and called inside '<img
> src="/ImageAction">' or '<html:img action="/ImageAction"/>'?
>
> SB
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

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