Return-Path: Delivered-To: apmail-struts-user-archive@www.apache.org Received: (qmail 89496 invoked from network); 5 Jan 2010 16:08:34 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 5 Jan 2010 16:08:34 -0000 Received: (qmail 37124 invoked by uid 500); 5 Jan 2010 16:08:31 -0000 Delivered-To: apmail-struts-user-archive@struts.apache.org Received: (qmail 37046 invoked by uid 500); 5 Jan 2010 16:08:31 -0000 Mailing-List: contact user-help@struts.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Struts Users Mailing List" Reply-To: "Struts Users Mailing List" Delivered-To: mailing list user@struts.apache.org Received: (qmail 37036 invoked by uid 99); 5 Jan 2010 16:08:31 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Jan 2010 16:08:31 +0000 X-ASF-Spam-Status: No, hits=-4.0 required=10.0 tests=RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [155.91.38.111] (HELO wily.merck.com) (155.91.38.111) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Jan 2010 16:08:20 +0000 X-IronPort-AV: E=Sophos;i="4.47,506,1257138000"; d="scan'208";a="260943884" Received: from unknown (HELO ipmh4.merck.com) ([54.62.195.229]) by wily.merck.com with ESMTP; 05 Jan 2010 11:07:56 -0500 X-IronPort-AV: E=Sophos;i="4.47,506,1257138000"; d="scan'208";a="24047339" Received: from usctgw1104.merck.com ([54.50.132.137]) by ipmh4.merck.com with ESMTP; 05 Jan 2010 11:07:54 -0500 Received: from USCTMX1140.merck.com ([54.50.72.134]) by usctgw1104.merck.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 5 Jan 2010 11:07:54 -0500 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Subject: RE: Displaying an image in JSP in struts+tiles project Date: Tue, 5 Jan 2010 11:07:53 -0500 Message-ID: <2CDB225E3067C043A2FF13D8844F5D180383A5EA@USCTMX1140.merck.com> In-Reply-To: <27020146.post@talk.nabble.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Displaying an image in JSP in struts+tiles project thread-index: AcqNipnexPkFKquMR+29xhOZr9g7mwAlXQ8A References: <27020146.post@talk.nabble.com> From: "Kawczynski, David" To: "Struts Users Mailing List" X-OriginalArrivalTime: 05 Jan 2010 16:07:54.0201 (UTC) FILETIME=[3D00D490:01CA8E21] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Being a fan of the KISS policy... I played around with=20 this but didn't have the time to figure it out, so I=20 made the URL spat out by struts2 points to a servlet=20 instead of struts2. =20 (Note that my web.xml has struts2 configured to listen=20 for *.action rather then slash-star) Good luck & please let me know what your solution is. Thanks! -dave > -----Original Message----- > From: Aruna Ponaka [mailto:aruna.hcu@gmail.com]=20 > Sent: Monday, January 04, 2010 5:09 PM > To: user@struts.apache.org > Subject: Displaying an image in JSP in struts+tiles project >=20 >=20 > Hi, >=20 > Am building an application in struts2 and tiles. My requirement is to > retrieve an image blob from mysql database and display the=20 > image in a jsp > using img tag as below.. >=20 > img src=3D""=20 >=20 > Part of my struts.xml is as below: >=20 > > > class=3D"org.apache.struts2.views.tiles.TilesResult" /> > class=3D"com.icensa.action.MyBytesResult" >
>
> > =20 > >
> My MyBytesResult class is: >=20 > public class MyBytesResult implements Result { >=20 > private static final long serialVersionUID =3D 1L; > =09 >=20 > public void execute(ActionInvocation invocation) throws=20 > Exception { > =09 > MyAction action =3D (MyAction) invocation.getAction(); > HttpServletResponse response =3D=20 > ServletActionContext.getResponse(); >=20 > response.setContentType("image/jpeg"); > =09 > //response.setContentLength(action.getMyContentLength()); >=20 > =09 > response.getOutputStream().write(action.getMyImageInBytes()); > response.getOutputStream().flush(); > } >=20 > } >=20 > And MyAction class is: >=20 > public class MyAction extends ActionSupport { > =09 > private static final long serialVersionUID =3D 1L; > Blob image =3D null; > Connection con =3D null; > Statement stmt =3D null; > ResultSet rs =3D null; > byte[] imgData =3D null; > OutputStream o =3D null; > HttpServletResponse response =3D ServletActionContext.getResponse(); > public String doDefault() { > System.out.println("doDefault()"); > try { > Class.forName("com.mysql.jdbc.Driver"); > con =3D > DriverManager.getConnection("jdbc:mysql://localhost:3306/proje > ct","root","pass"); > stmt =3D con.createStatement(); > rs =3D stmt.executeQuery("select * from=20 > books_tb where > category=3D'General' order by publish_date desc"); > while (rs.next()) { > image =3D rs.getBlob(11); > imgData =3D=20 > image.getBytes(1,(int)image.length()); =20 > }=20 > } > catch (Exception e) { > System.out.println(e.getMessage());=09 > =20 > }=20 > return "myImageResult"; > } >=20 > public byte[] getMyImageInBytes() {=20 > System.out.println("getMyImageInBytes()"); > try{ > =20 > } > catch (Exception e) { > System.out.println(e.getMessage()); > =20 > }=20 > return imgData; > } >=20 > // public String getMyContentType() { } > // public String getMyContentDisposition() {} > // public int getMyContentLength() { } > // public int getMyBufferSize() { } >=20 > } >=20 > when i run the code the image is not displayed and I get an=20 > error saying > No result defined for action com.action.MyAction and result success >=20 > In struts.xml is I provide reslut name=3D"success" and the jsp,=20 > it does not > throw an error but not displaying the image. However in any=20 > case it is not > going to MyAction.java. What could i do to rectify this? > Could provide you with required code if necessary.. >=20 > Thanks, > Aruna=20 >=20 > --=20 > View this message in context:=20 > http://old.nabble.com/Displaying-an-image-in-JSP-in-struts%2Bt iles-project-tp27020146p27020146.html > Sent from the Struts - User mailing list archive at Nabble.com. >=20 >=20 > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org > For additional commands, e-mail: user-help@struts.apache.org >=20 >=20 Notice: This e-mail message, together with any attachments, contains infor= mation of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New Jerse= y, USA 08889), and/or its affiliates Direct contact information for affilia= tes is available at http://www.merck.com/contact/contacts.html) that may be= confidential, proprietary copyrighted and/or legally privileged. It is int= ended solely for the use of the individual or entity named on this message.= If you are not the intended recipient, and have received this message in e= rror, please notify us immediately by reply e-mail and then delete it from = your system. --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@struts.apache.org For additional commands, e-mail: user-help@struts.apache.org