将此文件保存为InputImagejsp文件其中testimagejsp文件是用来将图片数据存入数据库的具体代码如下所示
<%@ page contentType=
text/html;charset=gb
%>
<%@ page import=javasql* %>
<%@ page import=javautil*%>
<%@ page import=javatext*%>
<%@ page import=javaio*%>
<jsp:useBean id=conn scope=page class=dbconnDBResult/>
<%
String path = requestgetContextPath();
String basePath = requestgetScheme()+://+requestgetServerName()+
:+requestgetServerPort()+path+/;
%>
<!DOCTYPE HTML PUBLIC //WC//DTD HTML Transitional//EN>
<html>
<head>
<base href=<%=basePath%>>
<title>My JSP testimagejsp starting page</title>
<meta httpequiv=pragma content=nocache>
<meta httpequiv=cachecontrol content=nocache>
<meta httpequiv=expires content=>
<meta httpequiv=keywords content=keywordkeywordkeyword>
<meta httpequiv=description content=This is my page>
<!
<link rel=stylesheet type=text/css href=stylescss>
>
</head>
<body>
<%
requestsetCharacterEncoding(gb);
//建立Statement对象
String picname=requestgetParameter(picname);
String pic=requestgetParameter(pic);
//获得所要显示图片的标题存储路径内容并进行中文编码
FileInputStream str=new FileInputStream(pic);
String sql=insert into p(picnamepic) values(??);
PreparedStatement pstmt=conngetPreparedStatement(sql);
pstmtsetString(picname);
pstmtsetBinaryStream(strstravailable());
pstmtexecute();
//将数据存入数据库
outprintln(SuccessYou Have Insert an Image Successfully);
%>
</body>
</html>
网页中动态显示图片
接下来我们要编程从数据库中取出图片其代码如下所示
[] [] [] []