• Post Reply Bookmark Topic Watch Topic
  • New Topic

Custom tag and Image  RSS feed

 
Hardik Patel p
Ranch Hand
Posts: 40
Hibernate Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends,

I am developing shopping cart in which I am storing image in database and retrieving.

When I select any product category from menu. example, I selected Computer then all list of product related to computer will be return i.e productName, Price and image, By using JSON.

this is my json response and output in comment.



Alternatively I created custom tag to resolve this.Custom tag is working fine in jsp but in java script it saying error raised Unterminated custom tag. I think I used this custom tag in javascript but i am not sure about this error,

custom tag code for image :



MY Question
1 - How can I use Custom tag in javascript ? Or
2 - How can we extract image from json object, like I did in custom tag .

Please give solution of above.

Thank you
Hardik
 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hardik,

I think storing images in database is not good idea.

Keep your images in filesystem and just keep the image name in database
 
Hardik Patel p
Ranch Hand
Posts: 40
Hibernate Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Mahtab Alam,

I am doing this for just learning purpose. Please give solution if you have.

and friends I forgot to write this.



Thank you
Hardik
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My Answers:

1: You can't execute the custom tag directly in javascript. It's that whole client side vs server side thing.

2: I think the bit you need to fix is where you SET the json data (i.e. your showProductsByCategory server side code). You haven't shown us that part of it. What value do you put into the image attribute? I'm presuming it should be the Base64 encoding of the image (like you did in the custom tag).
 
Paul Clapham
Sheriff
Posts: 22690
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you trying to pass the image data from the database to the HTML via JSON? You could conceivably do that, but the HTML isn't going to be able to display that image data as an image, so it's pretty pointless.

The standard thing to do is to have a normal image tag in your HTML which points to a servlet which will extract the image from the database (or wherever you decide to store it) and return that data as an image. Google for "image servlet" and you should find a lot of examples of that.
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>You could conceivably do that, but the HTML isn't going to be able to display that image data as an image
I thought so too, but it appears that it IS possible: http://css-tricks.com/data-uris/
If you use a data:image url you can include the image as a base64 encoded string.

Obviously being base64 encoded, it will be larger than the original image, but it all comes back in that one stream, so saves another HTTP connection.
So if it actually sends back a base64 encoded string, it should theoretically work.

My guess as to what has gone wrong here is either
- the image data hasn't been base64 encoded
- the property for the image (data[key].image) resolves to an object rather than the image data, and further property references are required. e.g. data[key].image.base64encodedDataAttribute


 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66257
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
data uris are generally frowned upon as it means that the image cannot be cached and all the image data must be sent every time the page is loaded.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!