Reputation: 626
I am working on GWT and the following is my code:
if(rs1.next()){
int len = imgLen.length();
byte [] rb = new byte[len];
InputStream readImg = rs1.getBinaryStream(1);
int index=readImg.read(rb, 0, len);
System.out.println("hello");
System.out.println("index"+index);
//st.close();
response.reset();
response.setContentType("image/png");
System.out.println("response"+response);
int len3 = 0;
while ((len = readImg.read(rb)) != -1) {
response.getOutputStream().write(rb,0,len);
System.out.println( response);
}
I use this code to retrieve the image from mySQL database at server side. Its response at client side is "IMG src="http://some path:8888/m/upload" url. So does anybody know how to retrieve the image at client side?
Upvotes: 0
Views: 2197
Reputation: 7300
The question is not GWT specific per say. It looks like you have images stored in your datase and you want to make them available to a web page (in your case the client side of your GWT application).
create a servlet that accepts the image id or whatever as a parameter, reads the image from the database and writes it out to the response.getOutputStream (it looks like you have that code already, just put it in a standalone servlet).
give a path to your image servlet in web.xml for example servlet mapping is /db-images
your images stored in the database are now accessible at http://your-server/your-app-context/db-images?id=123
Upvotes: 2
Reputation: 7244
Well you could be a little more precise at asking your question. But from what I understand you're trying to display an image from a URL? Maybe this will help.
http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/user/client/ui/Image.html
Upvotes: 0