通过 gwt 中的图像 src url 检索图像
我正在使用 GWT,以下是我的代码:
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);
}
我使用此代码从服务器端的 mySQL 数据库检索图像。它在客户端的响应是“IMG src="http://some path:8888/m/upload”url。那么有人知道如何在客户端检索图像吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个问题并不是 GWT 具体的。看起来您的数据集中存储了图像,并且您希望将它们提供给网页(在您的情况下为 GWT 应用程序的客户端)。
创建一个 servlet,它接受图像 id 或其他任何内容作为参数,从数据库读取图像并将其写入到 response.getOutputStream(看起来您已经有了该代码,只需将其放入独立的 servlet 中即可) .
在 web.xml 中给出图像 servlet 的路径
例如 servlet 映射是 /db-images
现在可以通过 http://your-server/your-app-context/db-images?id=123
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
好吧,你可以更准确地提出你的问题。但据我了解,您正在尝试显示来自 URL 的图像?也许这会有所帮助。
http:// /google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/user/client/ui/Image.html
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