⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 show_product_image.java

📁 显示产品图片的servlet,从数据库里取图片
💻 JAVA
字号:

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class show_product_image extends HttpServlet
{


public void doGet(HttpServletRequest request,
                     HttpServletResponse response)
       throws IOException, ServletException
   {
       xcfi.data_conn.mssql_conn myconn=new xcfi.data_conn.mssql_conn();
       try{
       myconn.getConn();

       String p=request.getParameter("id");
       String procedure = "{call sun_select_image_by_product_no(?) }";
       CallableStatement cstmt = myconn.conn.prepareCall(procedure);
       ResultSet rs;
       cstmt.setString(1,p);
       rs=cstmt.executeQuery();
       byte [] buf=null;
       String type="";

       if (rs.next()){
       buf = rs.getBytes("image");
//type=rs.getString("type");

       }else
       {
       buf = new byte[0];
       }
       response.setContentType("image/gif");
       response.setHeader("cache-control", "no-cache");

       /*if(type.compareTo("wbmp")==0)response.setContentType("image/vnd.wap.wbmp");
       if(type.compareTo(".gif")==0)response.setContentType("image/gif");
       if(type.compareTo(".jpg")==0)response.setContentType("image/jpeg");
       if(type.compareTo(".png")==0)response.setContentType("image/png"); */
//图片输出的输出流
       OutputStream out1 = response.getOutputStream();
//将缓冲区的输入输出到页面
       out1.write(buf);
       out1.flush();
//out.println("type:"+type);

       rs.close();
       rs=null;
       cstmt.close();
       cstmt=null;
       myconn.conn.close();
   }
    catch(java.sql.SQLException e){System.out.println("servlet:show_product_image error info: "+e.toString());}
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -