struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aruna Ponaka <>
Subject RE: Displaying an image in JSP in struts+tiles project
Date Mon, 11 Jan 2010 20:15:51 GMT

I wrote an action class and it worked. 
I called the action class like below...

img src="<s:url action="imgAction"></s:url>

and the struts.xml 

         <action name="imgAction" class="com.icensa.action.ImageAction">           
               <result type="tiles">books</result>

import java.sql.Blob;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

public class ImageAction extends ActionSupport {
	private static final long serialVersionUID = 1L;
	private byte[] img=null;
	private int id = 0;
	Blob image = null;
       Connection con = null;
       Statement stmt = null;
       ResultSet rs = null;
       byte[] imgData = null;
       OutputStream o = null;
       HttpServletResponse response = ServletActionContext.getResponse();
	public String execute() {
		try {
		      con =
		      stmt = con.createStatement();
		      rs = stmt.executeQuery("select * from books_tb where
category='Social and Economic' order by publish_date desc");
		      while ( {
			        image = rs.getBlob(10);
			        imgData = image.getBytes(1,(int)image.length());		         
				System.out.println("id   "+getId());
		        OutputStream out = response.getOutputStream();
		        return null;
		catch (Exception e) {
		return null;

I was using doDefault function earlier and was trying to return the
outputstream, but that will not work and it should return null.

Hope this is useful to someone....

View this message in context:
Sent from the Struts - User mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message