81,091
社区成员
发帖
与我相关
我的任务
分享
<%
out.clear();
out=pageContext.pushBody();
response.sendRedirect("photo.jsp");
%>
</div>
<div id="section">
<%--<jsp:include page="photo.jsp"/>--%>
<img style="width: 50%;height: 50%" src="photo.jsp"/>1234
</div>
<%
//数据库用户名
String userName = "root";
//密码
String userPasswd = "nxycmjh19960622";
//数据库名
String dbName = "student";
//联结字符串
String url = "jdbc:mysql://localhost:3306/student";
Connection photoConn;
ResultSet photoRs=null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
photoConn=DriverManager.getConnection(url,userName,userPasswd);
Statement photoStatement=photoConn.createStatement();
photoRs=photoStatement.executeQuery("select photos1 from photos where studentId='201430001'");
if(photoRs.next()){
Blob blob=photoRs.getBlob("photos1");
int size=(int)blob.length();
out.print(size);
InputStream inputStream=blob.getBinaryStream();
byte[] bytes=new byte[size];
response.setContentType("image/jpeg");
ServletOutputStream servletOutputStream=response.getOutputStream();
int bytesRead=0;
while((bytesRead=inputStream.read(bytes))!=-1){
servletOutputStream.write(bytes,0,bytesRead);
}
inputStream.close();
servletOutputStream.flush();
servletOutputStream.close();
out.clear();
}
%>