我用servlet读取数据库图片文件已经成功
来源:互联网 发布:用数据库统计访问次数 编辑:程序博客网 时间:2024/05/04 08:05
我用servlet读取数据库图片文件已经成功
可以单独显示
现在要在jsp页面上显示出来,同时显示其他详细信息
需要如何设置
使用 <img>还是其他的
servlet主要代码
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->import java.io.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;import java.sql.*;public class imageShow extends HttpServlet { private ServletConfig config; //初始化Servlet final public void init(ServletConfig config) throws ServletException { this.config = config; } //处理GET请求 public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { doPost(request,response); } //响应POST请求 protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=GBK"); ServletOutputStream sout=response.getOutputStream(); try { Class.forName("com.mysql.jdbc.Driver"); }catch(ClassNotFoundException ce) { sout.println(ce.getMessage()); } try { //建立数据库连接 String url="jdbc:mysql://localhost:3306/test"; String user="root"; String pass=""; Connection conn=DriverManager.getConnection(url,user,pass); String temp=request.getParameter("id"); int id=Integer.parseInt(temp); String sql = "select picture from book where id ="+id; Statement stmt=conn.createStatement(); ResultSet rs=stmt.executeQuery(sql); InputStream in=null; if(rs.next()) { in=rs.getBinaryStream("picture"); //ServletOutputStream sout=response.getOutputStream(); byte image[]=new byte[1024]; while(in.read(image)!=-1) { sout.write(image); } sout.flush(); //sout.close(); rs.close(); stmt.close(); conn.close(); //response.sendRedirect("pleaselogin.jsp?errorMessage=1"); return; //request.getRequestDispatcher("/site2/index.jsp").forward(request,response); } } catch (Exception e){ sout.println("图片不能显示.<br>"); sout.println("Error : " + e.toString()); } }}
阅读全文
0 0
- 我用servlet读取数据库图片文件已经成功
- servlet读取数据库图片文件
- 用servlet读取图片
- C#读取已经被占用的文件
- 从数据库中读取并生成图片的Servlet
- 从数据库中读取并生成图片的Servlet
- delphi 实现数据库读取图片文件。
- delphi 实现数据库读取图片文件
- [code]RCP中使用Servlet读取图片文件并输出
- 文件读取(读取图片)
- servlet读取文件
- servlet读取properties文件
- servlet读取资源配置文件
- java servlet 读取图片 相应
- 怎么用jquery检查图片是否已经加载即加载是否成功
- 用C#编程从数据库中读取图片数据导进Excel文件的方法
- 读取数据库(SQL Server)中的文件(图片例子)
- 从数据库中读取blob字段并生成图片文件
- 纽约市想成为VR/AR的“全球中心”
- java.util.Date、java.sql.Date与String
- Android实现手势监听
- 洛谷P1941 飞扬的小鸟
- DOM节点的易错点
- 我用servlet读取数据库图片文件已经成功
- 网页正文提取工具Beautiful Soup
- Android 扫描wifi局域网ip
- 学习路径
- Unity 键盘,鼠标,触摸输入
- 使用@Valid @RequestBody 的用意在于抛出notvalid的异常
- Windows下Git的下载和安装配置
- tolua++入门
- Oracle中对超长内容的处理,避免出现can bind a LONG value only for insert into a LONG column错误