📄 showimage.java
字号:
import java.io.IOException;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/*
* Created on 2004-6-30
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
/**
* @author haoyulong
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class ShowImage extends HttpServlet {
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
//TODO Method stub generated by Lomboz
doPost(request,response);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
//TODO Method stub generated by Lomboz
java.sql.Connection conn;
java.lang.String strConn;
java.sql.Statement Stmt; //语句对象
java.sql.ResultSet sqlRst; //结果集对象
ServletOutputStream op = response.getOutputStream();
//PrintWriter out = response.getWriter();
//在数据库中的照片的ID
String photoid ="";
photoid = request.getParameter("photoid");
String SQLString = "select * from album where id =" + photoid;
try{
javax.naming.InitialContext ctx = new javax.naming.InitialContext();
javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("java:/MySqlDS");
conn = ds.getConnection();
Stmt = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
// 执行Sql语句
sqlRst=Stmt.executeQuery ( SQLString);
while(sqlRst.next()){
java.sql.Blob blob=sqlRst.getBlob( "data" );
byte[] ab = blob.getBytes(1, (int)blob.length());
response.setContentType("image/gif");
response.reset();
op.write(ab);
op.flush();
op.close();
}
Stmt.close ();
conn.close();
} catch (java.sql.SQLException e){
e.printStackTrace();
}catch (NamingException e){
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -