I'm trying to display a photo on my jsp file. a photo that is inside my images photos works fine but when i'm trying to retrieve a photo using a url from the internet it doesnt work.
my url is a link of a database domain.I'm saving my photos using blobstore in that domain and retrieve them later.
I know the link works fine because when I use it in my explorer I receive the photo I uploded so what could be wrong? or is there a better way to display photos on a jsp file using blobStore ?
I'v search the web for something similar but all the solutions are for photos save in the program or not displaying on jsp.
my code in the jsp file is :
<%String blob=request.getParameter("blob");
BlobKey blobKey = new BlobKey(blob);
ImagesService services = ImagesServiceFactory.getImagesService();
ServingUrlOptions serve = ServingUrlOptions.Builder.withBlobKey(blobKey);
String url = services.getServingUrl(serve);
%>
<center><img src="url" alt='photo'/></center>
I've tried printing the url I received to make sure it is the right path and it works fine when I put it in my explorer so what could be the problem ? thanks for your help
Syntax error.You cannot access variable like that. Have you tried the following?
<img src="<%= url %>" />
Related
So I'm using JFree chart and I'm trying to generate an image and display it in my jsp code. I would like to know how to accomplish this. I have tried multiple different ways but it doesn't work.
I saved the file and then when I try to access it. It is stored on the webserver and therefore I don't have the url to it?
Any help would be much appreciated.
I also tried to do something like this,
<IMG SRC="chart.jsp"
WIDTH="300" HEIGHT="300" BORDER="0" USEMAP="#chart">
which is basically jsp which generates an image. It works but how can pass parameters to it?
You shouldn't use a JSP, but a servlet to generate an image. JSPs are view components, whose role is to generate HTML markup from a model prepared by a controller.
But anyway, you pass parameters to a JSP the same way as you do for any other URL:
<img src="chart.jsp?param1=value1¶m2=value2" .../>
Instead of thinking of the img source as static file think of the url being a stream that will be returned from a servlet using a prticular URL
eg
<img src="/jfreeServer?param1=123"/>
I create pdf using Velocity template, but i am not able to put images in pdf.
I am adding url into context object and accessing that object into eot.vm file, url is going proper but still images are not displaying in pdf.
Thanks & Regards,
Tushar
Make sure that URL you are passing is sending IMAGE as response not an full html page.
i was passing URL that was sending me a whole html page, so i was unable to see images.
But now its fixed.
Please visit below link:
https://answers.atlassian.com/questions/2907/how-to-access-image-generated-via-velocity-template-confluence
I have one web application for capturing image from webcaam using flash player.
after capturing image from webcam I am displaying it's preview in HTML img tag and also capturing image url in hidden form fields which I am using to store that image in my database. But my query is how do I store that image from that image tag as blob in my database and most of the solution I reviewed in that I found of storing image in database were uploading image from system and then storing and retrieving it from databse.
In order for this to work, you need to create a <form enctype="multipart/form-data"> . In your html, insert a file upload control. Then you have to select the file to upload (this cannot be done automatically because of security reasons in most browsers). And then submit your form.
When form is submitted, you can read image from request and store it to db ( how to upload a image in jsp and store database as blob )
I have a table with images stored in it as BLOB. I'm using JPA/Hibernate. Images are mapped to a bean field with type blob. Now my Spring controller is returning entire list of bean (each object of this bean has a blob object) to my jsp. I want to display all the images on that jsp.
I tried to use some thing like this on my jsp:
<c:forEach items="${itemList}" var="item" varStatus="status" >
<img src="<c:out value="${item.image}" />"/><br/> /*<img src="${item.image}"/> */
</c:forEach>
but that is not working. Instead of getting the list of images displayed on jsp , I 'm getting the class name, when I view the page source I saw something like this <img src="java.object.serilizableBlob#2134"/>
Please help me delve with the problem. How can I display all the images on same jsp.
The <img src> has to point to an URL, not to a toString() representation of some blob object. The webbrowser wouldn't understand how to download it and it will effectively end up in a HTTP 404 error.
You rather want to end up with for example this:
<img src="url/to/image.png" />
To serve images dynamically from a database, use a servlet. You should then instead of a list of blobs have a list of unique image IDs/filenames so that your HTML end up like this
<img src="imageservlet/image1.png" />
<img src="imageservlet/image2.png" />
<img src="imageservlet/image3.png" />
This way the browser can download the images by URL and display them accordingly.
No, printing binary data among all that HTML won't help. The data URI scheme comes close, but this isn't fully supported in all modern browsers.
See also:
How to retrieve and display images from a database in a JSP page? - this shows the "raw JDBC" example, but the idea is the same for JPA/Hibernate; just get a byte[] or an InputStream of the DB somehow and write it to the OutputStream of the response after having set the necessary response headers so that the browser understands how to deal with it.
I have an image in the blobstore of my GAE . I need to retrieve it and make some trasformations and finally display it in my jsp page.
Currently I used,
BlobKey blobKey = new BlobKey(req.getParameter("blob-key"));
blobstoreService.serve(blobKey, res);
This shows the picture but I want to retrieve it as an 'Image' type and resize it using the code below
ImagesService imagesService = ImagesServiceFactory.getImagesService();
Image oldImage = ImagesServiceFactory.makeImageFromBlob(blobKey);
Transform resize = ImagesServiceFactory.makeResize(200, 300);
Image newImage = imagesService.applyTransform(resize, oldImage);
byte[] newImageData = newImage.getImageData();
How will I display my 'newImage' in a jsp page? It would be very helpful if I could see an example code. I would also like to know if there is any way i can get the blob-key of the images I presently have in my blobviewer.
You should not process the image in the request for your JSP page.
You have to take two steps:
1.
Render a JSP page that contains an image tag like
<img src="mydomain.com/getImage?blob-key=123435"/>
2.
Have a separate servelt mapped to mydomain.com/getImage that outputs the image with the given id.
So all the code you presented above will go in the servlet that delivers the image and not in the JSP delivering code. And then the image can be delivered using the HTTPResponses OutputStream. And don't forget to set the correct content type and length for the response.