You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Turner Benjamin <Be...@cronos.be> on 2004/02/12 12:30:43 UTC

struts actions and content/type responses

hello,

i am looking for a solution for the following problem:

in my database i have various BLOB items which represent images (gif or jpg). i would like to create a struts action which returns this (by passing along a request parameter to the action which is the imageid in the database. is it possible to set the response content/type in an action and then return the image itself somehow? maybe with a requestdispatcher? any ideas/pointers to this would be welcome.

ty,

Ben

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


Re: struts actions and content/type responses

Posted by Mark Lowe <ma...@talk21.com>.
Hi ben

I assume you know how to get request parameters, construct query 
strings and get a byte array from you db. Here's some code that will 
stream an image. This should get you far enough to adapt to you needs. 
if you use an action just return null instead of a forward, or just use 
a servlet. There was another way of doing this by creating a fascade so 
the possibility to get images in the way would always be possible, but 
I dont recall the details and although it was quite clever, the example 
i saw involved ugly code being added to html pages.

response.setContentType("image/jpeg");

String imageStr = "file:///image/foo.jpg";

OutputStream ou = response.getOutputStream();
java.net.URI imgUri = new java.net.URI(imageStr);
File imageFile = new File(imgUri);
RandomAccessFile raf = new RandomAccessFile( imageFile, "r" );
FileInputStream imageFileStream = new FileInputStream(imageFile);

//if you om returns a byte[] then you can probably start here.
byte[] image = new byte[(int) imageFile.length()];

while ( (raf.read( image )) > 0 ){
	ou.write( image );
}

ou.flush();
ou.close();

Cheers Mark


On 12 Feb 2004, at 12:30, Turner Benjamin wrote:

> hello,
>
> i am looking for a solution for the following problem:
>
> in my database i have various BLOB items which represent images (gif 
> or jpg). i would like to create a struts action which returns this (by 
> passing along a request parameter to the action which is the imageid 
> in the database. is it possible to set the response content/type in an 
> action and then return the image itself somehow? maybe with a 
> requestdispatcher? any ideas/pointers to this would be welcome.
>
> ty,
>
> Ben
>
> ---------------------------------------------------------------------
> 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


strut1.1 installationon weblogic8.1

Posted by Jignesh Patel <jp...@bangracing.com>.
 Hi Friend's
 I am trying to install strut1.1 on the weblogic8.1
 Any body guide me for the same?
 -jignesh

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


RE: struts actions and content/type responses

Posted by Andrew Hill <an...@gridnode.com>.
http://www.catb.org/~esr/faqs/smart-questions.html

-----Original Message-----
From: Jignesh Patel [mailto:jpatel@bangracing.com]
Sent: Thursday, 12 February 2004 19:42
To: Struts Users Mailing List
Subject: Re: struts actions and content/type responses


Hi Friend's
I am trying to upload strut1.1 on the weblogic8.1
Any body guide me for the same?
-jignesh

---------------------------------------------------------------------
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


Re: struts actions and content/type responses

Posted by Jignesh Patel <jp...@bangracing.com>.
Hi Friend's
I am trying to upload strut1.1 on the weblogic8.1
Any body guide me for the same?
-jignesh

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


Re: struts actions and content/type responses

Posted by Michael McGrady <mi...@michaelmcgrady.com>.
I provided the code to do this about two weeks ago on this list.

At 03:30 AM 2/12/2004, you wrote:
>hello,
>
>i am looking for a solution for the following problem:
>
>in my database i have various BLOB items which represent images (gif or 
>jpg). i would like to create a struts action which returns this (by 
>passing along a request parameter to the action which is the imageid in 
>the database. is it possible to set the response content/type in an action 
>and then return the image itself somehow? maybe with a requestdispatcher? 
>any ideas/pointers to this would be welcome.
>
>ty,
>
>Ben
>
>---------------------------------------------------------------------
>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


RE: struts actions and content/type responses

Posted by Andrew Hill <an...@gridnode.com>.
Your ImageAction could stream the result in the appropriate format itself.

When done, return null instead of an ActionForward to indicate to struts
that the Action has already handled writing the response.

Not sure what headers etc... need to be set though. If you search the
archive you can probably find some examples.

hth
Andrew

-----Original Message-----
From: Turner Benjamin [mailto:Benjamin.Turner@cronos.be]
Sent: Thursday, 12 February 2004 19:31
To: Struts-User (E-mail)
Subject: struts actions and content/type responses


hello,

i am looking for a solution for the following problem:

in my database i have various BLOB items which represent images (gif or
jpg). i would like to create a struts action which returns this (by passing
along a request parameter to the action which is the imageid in the
database. is it possible to set the response content/type in an action and
then return the image itself somehow? maybe with a requestdispatcher? any
ideas/pointers to this would be welcome.

ty,

Ben

---------------------------------------------------------------------
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


how to send checkbox value?

Posted by Sathish Babu K R <kr...@yahoo.com>.
hi all

i have a prob in sending checkbox value.

i like to send check box value of a page to another
page when a link is clicked which does not go thru any
form.its a struts environment

sathish



__________________________________
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html

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