怎样显示存放在数据库中的图片? 创建一个临时文件,页面上<img>引用这个文件。好像没有别的方法了。如果是应用程序还可以通过流直接创建Image. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在网页中显示数据库中的图形的方法:举例如下:1、主Html文件:<html><title><head>显示数据库中图形文件</head></title><body><h1>显示数据库中的图形文件</h1><img src="http://localhost/getSketch?ID=1"><body></html>2、取得图形信息的Servlet1中的getSketch是一个Servlet,代码如下:import javax.servlet.*;import javax.servlet.http.*;import java.io.*;import java.util.*;public class getSketch extends HttpServlet{ protected void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException , IOException{ doGet(req,res); } protected void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException , IOException{ //得到参数值 String ls_ID=req.getParameter("ID"); java.sql.Connection con; java.sql.Statement stmt_Sketch; java.sql.ResultSet rs_Sketch; try{ //连接数据库,略... stmt_Sketch = con.createStatement(); rs_Sketch = stmt_Sketch.executeQuery("select sketch from sketchTable where ID="+ls_ID); res.setContentType("Image/gif"); if(rs_Sketch.next()){ ServletOutputStream out = res.getOutputStream(); //输出二进制流 java.io.InputStream in=rs_Sketch.getBinaryStream("sketch"); byte b[]=new byte[1000]; while(true){ int readLength=in.read(b); if(readLength==-1) break; out.write(b,0,b.length); } out.flush(); out.close(); } rs_Sketch.close(); stmt_Sketch.close(); con.close(); }catch(Exception ex){ throw new ServletException(ex); } }} jS谁帮我一下点击A变颜色带图片的代码 js问题 weblogic下网页无法显示 tomcat中server.xml文件的配置 100分 分页求解 请教一个服务端读取pdf文件,并由客户端处理的问题。 为大家提供一个交友,学习的平台 为何我的JSP例程不运行? 有心人指点一下!!! 在jsp中联接mysql??? 怎样才能做到当鼠标在网页上移动时,鼠标后面有一个字跟着一起,并且随着鼠标移动的快慢,字之间的距离也不一样?? 看看这个大作业,帮忙写一下100元/分!
<html>
<title><head>显示数据库中图形文件</head></title>
<body>
<h1>显示数据库中的图形文件</h1>
<img src="http://localhost/getSketch?ID=1">
<body>
</html>
2、取得图形信息的Servlet
1中的getSketch是一个Servlet,代码如下:
import javax.servlet.*;
import javax.servlet.http.*;import java.io.*;
import java.util.*;public class getSketch extends HttpServlet{
protected void doPost(HttpServletRequest req,HttpServletResponse res)
throws ServletException , IOException{
doGet(req,res);
}
protected void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException , IOException{
//得到参数值
String ls_ID=req.getParameter("ID");
java.sql.Connection con;
java.sql.Statement stmt_Sketch;
java.sql.ResultSet rs_Sketch;
try{
//连接数据库,略...
stmt_Sketch = con.createStatement();
rs_Sketch = stmt_Sketch.executeQuery("select sketch from sketchTable where ID="+ls_ID);
res.setContentType("Image/gif");
if(rs_Sketch.next()){
ServletOutputStream out = res.getOutputStream();
//输出二进制流
java.io.InputStream in=rs_Sketch.getBinaryStream("sketch");
byte b[]=new byte[1000];
while(true){
int readLength=in.read(b);
if(readLength==-1)
break;
out.write(b,0,b.length);
}
out.flush();
out.close();
}
rs_Sketch.close();
stmt_Sketch.close();
con.close();
}catch(Exception ex){
throw new ServletException(ex);
}
}
}