我想实现上传照片以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 (系统找不到指定的文件。)大家有什么好的方法吗? 或者我这样写有什么问题吗?请指教,先谢过~~
<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 (系统找不到指定的文件。)大家有什么好的方法吗? 或者我这样写有什么问题吗?请指教,先谢过~~
解决方案 »
- 如何通过api学习java
- Spring里使用QueryRunner如何进行事物处理
- 我这样写为什么不能显示两个jsp页面,只能显示html页面,谢谢
- 有Apache和Tomcat通过JK2整合的高手进来一试~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- 高手都那里去了?这个问题一直都没有找到答案!
- 如何在Eclipse3.0+Jboss3.2.5+Lomboz环境下运行PetStore项目?请各位高手指点啊!
- 关于hibernate的one-to-one问题
- 关于用STRUTS框架来做WAP?
- 高分求助,如何在jsp程序中,生成一个日志文件!!!
- jbuider中Configur Servers的最大的困惑
- JSP较验
- java gmail email发送不成功
而不是用file得到流
用某apache的框架或smartupload等来做吧
别重复造轮子了
form类型错了
在后台可以用SmartUpload这个来上传.
这样不会出现找不到路径的问题了,但是照片信息存不进去,不知道是不是还应该设置什么参数?额,貌似很白痴但是很想不通过组件这样做出来,都是教材上的例子,太无语
确实是新手,刚上了课,在教材上抄个例子,就是调不通,用common包也出现好多问题,smartupload组件我在您那老是下载不下来,你给我发邮箱吧,我给你积分。[email protected],
那个jar我给你发了,不懂的可以问问呵呵