Well, your code makes absolutely no sense if you're trying to store the image as a blob--the only code I see copies a file from one place to another, and another one sets some string data for the same row.
In any case, if you're actually storing the image to the DB, you'd need to get those bytes and stream them to the client; searching the web for "display image from database" or something will provide a lot of solutions. Personally, I'm not a big fan of storing image data in a database, and generally store images on the file system. You'll still need to stream them to the client, though, with an image servlet, or in Struts 2, a "stream" result.
Joined: Jun 19, 2008
i have googled for tutorials regarding images but was not able to find one .....somebody please help me with finding the tutorials...or tell me the name of a good Struts2 book where information regarding images is specified.
I think what the OP is missing is the basic structure of an HTML page when images are to be displayed. I really think this needs to become an FAQ on the Ranch.
The view page (JSP or whatever) is going to create an HTML page to be displayed on the client (browser).
When the user performs the action that results in this response, the JSP page will produce an HTML page which includes contents which the application wants to show. For example, a page title, page header, page content, page footer, etc.
If you want the page content to include an image, the JSP doesn't just spit out the image content. Instead, the HTML content sent by the JSP page includes an <img> HTML tag.
When the image content is stored in the database (or even just on the server machine somewhere), you can create an Image Servlet to serve it. Let's say you create an Image Servlet named "MyImageServlet" and based on your servlet mappings, it is accessible via the following URL:
Then you can build your <img> tag as follows:
<img src="http://localhost/myApp/MyImageServlet?imageKey=myImage123 />
In your image servlet, you would get the request parameter named imageKey and use the value to look up the image in the database (or file system, whatever).
Now, as far as how to send the image back to the client, just reference the numerous examples available when you Google for image servlet (rather than duplicating that here).
As you can see, the image content is not sent as part of the original JSP response. The HTML content sent to the client by the JSP processing includes an HTML <img> tag which results in a separate request to the server.