!-- -- -- -- -- -- -- -- -- -- -- -- -- --servlet-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -->package Photo;import Javax.servlet.*;import javax.servlet.http.*;import java.io.*;import java.util.*;import java.lang.*;import java.sql.*;/*** <p>Title: </p>* <p>Description: </p>* <p>Copyright: Copyright (c) 2002</p>* <p>Company: </p>* @author unascribed* @version 1.0*/public class ShowImage extends HttpServlet { private static final String CONTENT_TYPE = "image/*"; /** * 定义数据库连接字符串,jdbc.odbc桥 */ private String driver_class = "Oracle.jdbc.driver.OracleDriver"; private String connect_string = "jdbc:oracle:thin:xxw/xxw@192.168.1.50:1521:ORCL"; Connection conn = null; ResultSet rs = null; Statement stmt = null; /******************************************** * 定义应用变量 ******************************************/ private String SQLString = ""; //定义查询语句
public String M_EorrMenage = ""; //定义错误信息变量 private InputStream in = null; //定义输入流
private int len = 10 * 1024 * 1024; //定义字符数组长度 //Initialize global variables public void init() throws ServletException { /** * 连接数据库
*/ try { Class.forName(driver_class); } catch (java.lang.ClassNotFoundException e) { //异常 System.err.println("databean():" + e.getMessage()); } } //Process the HTTP Get request public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(CONTENT_TYPE); PrintWriter out = response.getWriter(); //在数据库中的照片的ID int PHOTOID = 0; /********************************************* * 接受上文传递的图片ID号 * 上文传输文件名称为photoid *********************************************/ try { PHOTOID = Integer.parseInt(request.getParameter("photoid")); SQLString = "select * from xxw_photo where p_id=" + PHOTOID; } catch (Exception e) { e.printStackTrace(); response.setContentType("text/Html; charset=gb2312"); M_EorrMenage = "请输入图片ID号"; M_EorrMenage = new String(M_EorrMenage.getBytes("ISO8859_1"), "GBK"); out.println("<%@ page contentType=´text/html; charset=gb2312´ %>"); out.println("<html>"); out.println("<head><title>id</title></head>"); out.println("<body>"); out.println("<p>" + M_EorrMenage + "</p>"); out.println("</body></html>"); } /***************************************************** * 执行查询语句