Hint: perhaps a servlet?
Udara Amarasinghe wrote:Really are you sure that image will display if use <img scr"servlet?imageId=22" with other textual HTMl things.
Of course not. You can't return more than one response to a single request. The servlet would serve only the image. Why would it need to serve HTML too?
As I already explained. In the JSP you use an image tag to reference a servlet that returns the image data.
And you are still using Java scriptlets in JSPs? In 2011? And even so, the use of out.println() has never been proper practice. If you are still going to use scriptlets (even though they've been discredited for almost 10 years now), you would use scriptlet expressions.
Bear Bibeault wrote:Of course you can produce that. Why not? It's simple HTML!
Why all the confusion?
That solution not gives what I want. So I decide to try new technique that is store image in file system with user id as the name of image file and add path for image in <img scr="path"+<%=user.userId() %>
In your example (which is full of errors and which cannot work as shown): <img scr="path"+<%=user.userId() %>
If you replace the value of the src attribute with a servlet URL, it will work just the same.
Why are you resisting something so simple?
First write a method which retrieves the data from blob and saves the image as ".jpeg" format at server side and return the name of the created image file.
Now after you receive the file name from the method, you can give this as relative path to the <img> tag .
NOTE: Need to create a script to remove all the images which were created by above method once every week to improve the server memory.
That is really inefficient and needless. The image can be streamed directly from the DB (I assume that there's a good reason that the image is on a DB, otherwise, it'd already be in a file).
Smarty Ravi wrote:First write a method which retrieves the data from blob and saves the image as ".jpeg" format ...
Bear Bibeault wrote: That is really inefficient and needless. The image can be streamed directly from the DB (I assume that there's a good reason that the image is on a DB, otherwise, it'd already be in a file).
may be my way would be inefficient but this also forms a way to perform. Let me know if there is a solution for it. I am would be very happy to learn new things and efficient ways...
Udara Amarasinghe wrote:Mr. Bear Bibeault if you please can show the source code it will be very cool.
You know that's not the way things work here. But if you google, you'll find lots of example code.
Also, a CodeRanch staffer has provided this example which streams from a file, but can be adapted to read from a DB.