微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

二进制jpg图片上传小结

 前台jsp页面:putimage.jsp

<body>

  <form action="putimage.do"  method="post"
   ENCTYPE="multipart/form-data">
   <input name="file" type="file">
   <input type="submit" name="submit" value="上传">
  </form>
 </body>

 

Struts中action中的代码

FormFile file = pif.getFile();
 InputStream photoStream = file.getInputStream();//这里要特别注意和别的资料的区别
  try {
   new Image().putimg(file,photoStream,file.getFileSize());
  } catch (Exception e) {
   e.printstacktrace();
  }
  return mapping.findForward("success");

 

底层的一个dao方法

public void putimg(FormFile file,InputStream photoStream,int size) {   try {    Class.forName("com.microsoft.jdbc.sqlserver.sqlServerDriver");    String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=cmtony";    Connection conn = DriverManager.getConnection(url,"sa","sa");    PreparedStatement ps = null;    String sql = "insert into image(img) values (?)";    ps = conn.prepareStatement(sql);             ps.setBinaryStream(1,size);             ps.executeUpdate();             ps.close();             conn.close();   } catch (Exception e) {    e.printstacktrace();   }}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐