<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<img alt="" src="onload/by.jpg">
<form action="dosendFile.jsp" enctype="multipart/form-data" method="post">
<input type="file" name="myfile"><br>
<input type="submit" value="开始上传">
</form>
</body>
</html>
<%@page import="com.jspsmart.upload.File"%>
<%@page import="com.jspsmart.upload.SmartUpload"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
//创建SmartUpload对象
SmartUpload su = new SmartUpload();
//初始化
su.initialize(pageContext);
//声明一个File对象 用来接收上传的文件
File file = null;
//设置允许上传的文件类型
su.setAllowedFilesList("jpg,png,gif,");
//设置不允许上传的文件类型
su.setDeniedFilesList("bat,exe,mp4");
//设置单文件大小
su.setMaxFileSize(700000);
//设置总文件大小
su.setTotalMaxFileSize(800000);
//设置编码
su.setCharset("utf-8");
//开始上传
su.upload();
//获取文件集合中的第一个文件
file = su.getFiles().getFile(0);
String filePath = "";
if(!file.isMissing()){
//拼接文件上传到服务器的 路径
filePath = "onload/"+file.getFileName();
//上传到服务器 保存到指定路径
file.saveAs(filePath,SmartUpload.SAVE_VIRTUAL);
}
out.print("上传成功");
out.print("<img src='"+filePath+"'>");
%>