jsp中上传图片__完整代码

123xz 贡献于2014-05-08

作者 微软用户  创建于2012-04-12 07:38:00   修改者微软用户  修改于2012-04-12 07:39:00字数1745

文档摘要:jsp中上传图片__完整代码
关键词:

upfile.jsp
uploadimage.jsp uploadimage.jsp
   <%@ page language="java" pageEncoding="gb2312"%>  <%@ page    import="java.io.*,java.awt.image.*,com.sun.image.codec.jpeg.*,java.sql.*,com.jspsmart.upload.*,java.util.*"%>  <%@ page import="mainClass.*"%>            My JSP'uploadimage.jsp' starting page              <%       SmartUpload sma = new SmartUpload();       long file_max_size = 4000000;       String filename1 = "", ext = "", testvar = "";       String url = "uploadfiles/";       sma.initialize(pageContext);         try         {        sma.setAllowedFilesList("jpg,gif");        sma.upload();       } catch (Exception e) {      %>      <%   }     try {      com.jspsmart.upload.File myf = sma.getFiles().getFile(0);      if (myf.isMissing()) {  %>          <%       } else {       ext = myf.getFileExt();       int file_size = myf.getSize();       String saveurl = "";       if (file_size < file_max_size) {      Calendar cal = Calendar.getInstance();      String filename = String.valueOf(cal.getTimeInMills());      saveurl = request.getRealPath("/") + url;      saveurl += filename + "." + ext;      myf.saveAs(saveurl, sma.SAVE_PHYSICAL);      myclass mc = new myclass(request        .getRealPath("data/data.mdb"));      mc        .executeInsert("insert into [path] values('uploadfiles/"        + filename + "." + ext + "')");//检查      out.println("图片上传成功!");      response.sendRedirect("showimg.jsp");       }      }     } catch (Exception e) {      e.printStackTrace();     }    %>        

下载文档到电脑,查找使用更方便

文档的实际排版效果,会与网站的显示效果略有不同!!

需要 3 金币 [ 分享文档获得金币 ] 0 人已下载

下载文档