这个算法由我创建,算法用于使用jsp将图像存储到数据库中。为什么这个算法只能在Internet Explorer上运行?
insert.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form name="contact" action="first.jsp" method="post">
First name:
<input type=text name="sfname" value=""/><br>
Insert Image:
<input type=file name="sphoto" value=""/>
<br>
<button type="submit">SUBMIT</button>
</form>
</body>
</html>
first.jsp
first.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<%
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/snt","root","passoword");
PreparedStatement ps=con.prepareStatement("insert into imgtable(name,photo) values(?,?)");
String z=request.getParameter("sfname");
ps.setString(1," " +z+" ");
String zz=request.getParameter("sphoto");
String replaceString=zz.replace(":",":\\");
FileInputStream fin=new FileInputStream(""+replaceString+"");
ps.setBinaryStream(2,fin,fin.available());
int i=ps.executeUpdate();
out.println(i+" records affected");
if(i==1)
{
response.sendRedirect("insert.jsp");
}
con.close();
}catch (Exception e) {e.printStackTrace();}
//
%>
</body>
</html>
数据库表
create database snt
use snt
drop table imgtable
create table imgtable(
id int auto_increment primary key,
name text,
photo longblob
);