我想实现上传照片以blob字段形式保存到数据库中。 <form action="<%=request.getContextPath() %>/SetheadPhotoServlet" method="post" >
       <input type="file" name="photo" id="Path"/>
      <input type="submit" value="确定"></input>
 </form>
在Servlet中获取路径。
String photo = request.getParameter("photo");
//此时只能取到photo文件名,不能取到整个文件保存路径。Statement stmt = null;
FileInputStream fis = null;
InitialContext context = null;PreparedStatement preparedStmt = null;
File files = new File(fileStr);
         System.out.println(files.getPath()); 
String sql = "update basic_info set head_photo=? " + "where uid='"
+ uid + "';";
preparedStmt = conn.prepareStatement(sql);
preparedStmt.setBinaryStream(1, fis, (int) fis.available());
reslut = preparedStmt.executeUpdate();上传的时候出现java.io.FileNotFoundException: 42003_1.gif (系统找不到指定的文件。)大家有什么好的方法吗? 或者我这样写有什么问题吗?请指教,先谢过~~ 

解决方案 »

  1.   

    这种要用流的形式来写入,
    而不是用file得到流
    用某apache的框架或smartupload等来做吧
    别重复造轮子了
      

  2.   

    从request中获取到上传文件的输入流,你流了吗
      

  3.   

    <form action="xxx" method="post" enctype="multipart/form-data">
         form类型错了
    在后台可以用SmartUpload这个来上传.
      

  4.   

    一看lz代码就知道lz刚刚学JAVA,呵呵,别介意JSP上传可以用组件smartupload,这个组件我那边有下载http://download.csdn.net/source/2662879当然lz觉得不大想用组件,可以自己写一个,用apache的common包都可以实现
      

  5.   

    ServletInputStream fis = request.getInputStream();直接这样获取流?怎么能得到对应要上传文件的流呢?
    这样不会出现找不到路径的问题了,但是照片信息存不进去,不知道是不是还应该设置什么参数?额,貌似很白痴但是很想不通过组件这样做出来,都是教材上的例子,太无语
      

  6.   


    确实是新手,刚上了课,在教材上抄个例子,就是调不通,用common包也出现好多问题,smartupload组件我在您那老是下载不下来,你给我发邮箱吧,我给你积分。[email protected]
      

  7.   


    那个jar我给你发了,不懂的可以问问呵呵