enctype="multipart/form-data">uploadimage.jspuploadimage.jspimport="java.io.*,ja">

JSP中上传图片 完整代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

upfile.jsp

enctype="multipart/form-data">

enctype="multipart/form-data">

uploadimage.jsp

uploadimage.jsp

<%@ page language="java" pageEncoding="gb2312"%>

<%@ page

import="java.io.*,java.awt.image.*,com.sun.image.codec.jpeg.*,jav a.sql.*,com.jspsmart.upload.*,java.util.*"%>

<%@ page import="mainClass.*"%>

My JSP'uploadimage.jsp' starting page

<%

S martUpload sma = new SmartUpload();

l ong file_max_size = 4000000;

S tring filename1 = "", ext = "", testvar = "";

S tring url = "uploadfiles/";

s ma.initialize(pageContext);

t ry

{

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();

}

%>

相关文档
最新文档