我创建了下面的程序,当我按下提交按钮时,程序正在抛出FileNotFound异常。由于JSP页面无法找到完整的映像路径,问题即将到来。我调试了JSP程序,发现HTML表单仅传递没有路径的图像名称,这就是为什么问题即将到来。任何人都可以解决此问题。无法将图像存储到数据库
################## SQL Query ######################################
CREATE TABLE IMAGEMAIN(ID INTEGER,IMAGE BLOB) ;
################## HTML Form ######################
<form name="frm" method="post" action="index.jsp">
<input type="text" name="hint">
<input type="file" name="user_file">
<input type="submit">
################### JSP PAGE ########################
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Connection loaded");
Connection con = DriverManager.getConnection("jdbc:odbc:project","image","image");
System.out.println("Connection created");
String ll=request.getParameter("user_file");
String lo=request.getParameter("hint");
File imgfile = new File(ll);
FileInputStream fin = new FileInputStream(imgfile);
PreparedStatement pre = con.prepareStatement("insert into IMAGEMAIN (id,image) values(?,?)");
pre.setString(1,lo);
pre.setBinaryStream(2,fin,(int)imgfile.length());
pre.executeUpdate();
pre.close();
}
catch(Exception E)
{
out.println("the eror is "+ E);
}
快速谷歌,这里是你的解决方案:http://stackoverflow.com/questions/1142475/jsp-file-upload-with-apache-commons –