You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Fernandes Celinio <cf...@sopragroup.com> on 2009/11/27 12:44:27 UTC

[Struts 2 + EJB 3] Display an image

Hi,

I have an entity bean which has a BLOB attribute. That BLOB attribute
maps to a BLOB column in a table in an Oracle database.

@Entity
public class Boo implements Serializable {
 ...
@Lob
	@Basic(fetch=FetchType.LAZY)
	private byte[] image;
	
	public byte[] getImage() {
		return image;
	}

	public void setImage(byte[] image) {
		this.image = image;
	}

...
}

I also have an Action class where i query that entity bean and put the
result into the session :

public class MyAction extends ActionSupport implements SessionAware {
	...
  Public String someMethod() throws Exception {

		Boo boo = blaRemote.findById(l);
		session.put("boo ", boo );

...
}


Finally in my JSP i display the various values of the attributes of that
Entity bean, including that image attribute :

    <s:property value="#session.boo.attributeN" /> <br />	
    <img src="<s:property value="#session.boo.image" />" /> <br />	

Of course I can display the value of all attributes except the image.

How do you display an image with Struts 2 ? Is there a specific tag for
it ?

Thanks for helping.

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


RE: [Struts 2 + EJB 3] Display an image

Posted by Fernandes Celinio <cf...@sopragroup.com>.
Hi,
Thanks for helping.

Well, I of course needed to call the action in my <img> tag.

It works.
Thanks again.

-----Message d'origine-----
De : Paweł Wielgus [mailto:poulwiel@gmail.com] 
Envoyé : vendredi 27 novembre 2009 13:04
À : Struts Users Mailing List
Objet : Re: [Struts 2 + EJB 3] Display an image

Hi Fernandes,
i think that it is impossible what You are trying to achieve.
You cannot pur image to img tag inside html.
Img tag will result in just another http request, and this another request must be serviced by your server.

So the code will look like this:

<img src="/showMyimage.action?id=123" />

And showMyImage action will simply return image as a result.

Also read very carrefully above e-mail from Saeed!

Best greetings,
Paweł Wielgus.



2009/11/27 Saeed Iqbal <sa...@gmail.com>:
> Are you putting the file name in session string or the binary file?
>
> On Friday, November 27, 2009, Fernandes Celinio 
> <cf...@sopragroup.com> wrote:
>> Hi,
>>
>> I have an entity bean which has a BLOB attribute. That BLOB attribute 
>> maps to a BLOB column in a table in an Oracle database.
>>
>> @Entity
>> public class Boo implements Serializable {
>>  ...
>> @Lob
>>         @Basic(fetch=FetchType.LAZY)
>>         private byte[] image;
>>
>>         public byte[] getImage() {
>>                 return image;
>>         }
>>
>>         public void setImage(byte[] image) {
>>                 this.image = image;
>>         }
>>
>> ...
>> }
>>
>> I also have an Action class where i query that entity bean and put 
>> the result into the session :
>>
>> public class MyAction extends ActionSupport implements SessionAware {
>>         ...
>>   Public String someMethod() throws Exception {
>>
>>                 Boo boo = blaRemote.findById(l);
>>                 session.put("boo ", boo );
>>
>> ...
>> }
>>
>>
>> Finally in my JSP i display the various values of the attributes of 
>> that Entity bean, including that image attribute :
>>
>>     <s:property value="#session.boo.attributeN" /> <br />
>>     <img src="<s:property value="#session.boo.image" />" /> <br />
>>
>> Of course I can display the value of all attributes except the image.
>>
>> How do you display an image with Struts 2 ? Is there a specific tag 
>> for it ?
>>
>> Thanks for helping.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
> --
> Saeed Iqbal
> http://www.iqbalconsulting.com
> Struts - J2EE - Application Architect / Developer
>
> ---------------------------------------------------------------------
> 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


Re: [Struts 2 + EJB 3] Display an image

Posted by Paweł Wielgus <po...@gmail.com>.
Hi Fernandes,
i think that it is impossible what You are trying to achieve.
You cannot pur image to img tag inside html.
Img tag will result in just another http request,
and this another request must be serviced by your server.

So the code will look like this:

<img src="/showMyimage.action?id=123" />

And showMyImage action will simply return image as a result.

Also read very carrefully above e-mail from Saeed!

Best greetings,
Paweł Wielgus.



2009/11/27 Saeed Iqbal <sa...@gmail.com>:
> Are you putting the file name in session string or the binary file?
>
> On Friday, November 27, 2009, Fernandes Celinio
> <cf...@sopragroup.com> wrote:
>> Hi,
>>
>> I have an entity bean which has a BLOB attribute. That BLOB attribute
>> maps to a BLOB column in a table in an Oracle database.
>>
>> @Entity
>> public class Boo implements Serializable {
>>  ...
>> @Lob
>>         @Basic(fetch=FetchType.LAZY)
>>         private byte[] image;
>>
>>         public byte[] getImage() {
>>                 return image;
>>         }
>>
>>         public void setImage(byte[] image) {
>>                 this.image = image;
>>         }
>>
>> ...
>> }
>>
>> I also have an Action class where i query that entity bean and put the
>> result into the session :
>>
>> public class MyAction extends ActionSupport implements SessionAware {
>>         ...
>>   Public String someMethod() throws Exception {
>>
>>                 Boo boo = blaRemote.findById(l);
>>                 session.put("boo ", boo );
>>
>> ...
>> }
>>
>>
>> Finally in my JSP i display the various values of the attributes of that
>> Entity bean, including that image attribute :
>>
>>     <s:property value="#session.boo.attributeN" /> <br />
>>     <img src="<s:property value="#session.boo.image" />" /> <br />
>>
>> Of course I can display the value of all attributes except the image.
>>
>> How do you display an image with Struts 2 ? Is there a specific tag for
>> it ?
>>
>> Thanks for helping.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
> --
> Saeed Iqbal
> http://www.iqbalconsulting.com
> Struts - J2EE - Application Architect / Developer
>
> ---------------------------------------------------------------------
> 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


Re: [Struts 2 + EJB 3] Display an image

Posted by Saeed Iqbal <sa...@gmail.com>.
Are you putting the file name in session string or the binary file?

On Friday, November 27, 2009, Fernandes Celinio
<cf...@sopragroup.com> wrote:
> Hi,
>
> I have an entity bean which has a BLOB attribute. That BLOB attribute
> maps to a BLOB column in a table in an Oracle database.
>
> @Entity
> public class Boo implements Serializable {
>  ...
> @Lob
>         @Basic(fetch=FetchType.LAZY)
>         private byte[] image;
>
>         public byte[] getImage() {
>                 return image;
>         }
>
>         public void setImage(byte[] image) {
>                 this.image = image;
>         }
>
> ...
> }
>
> I also have an Action class where i query that entity bean and put the
> result into the session :
>
> public class MyAction extends ActionSupport implements SessionAware {
>         ...
>   Public String someMethod() throws Exception {
>
>                 Boo boo = blaRemote.findById(l);
>                 session.put("boo ", boo );
>
> ...
> }
>
>
> Finally in my JSP i display the various values of the attributes of that
> Entity bean, including that image attribute :
>
>     <s:property value="#session.boo.attributeN" /> <br />
>     <img src="<s:property value="#session.boo.image" />" /> <br />
>
> Of course I can display the value of all attributes except the image.
>
> How do you display an image with Struts 2 ? Is there a specific tag for
> it ?
>
> Thanks for helping.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

-- 
Saeed Iqbal
http://www.iqbalconsulting.com
Struts - J2EE - Application Architect / Developer

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