实现单个文件上传
------------------ upload.html--------------------
//上传文件页面
<html>
<head>
<title>文件上传</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<p align="center">上传文件选择</p>
<FORM method="POST" action="UpLoad.jsp" enctype="multipart/form-data">
<input type="hidden" name="TEST" value="good">
<table width="75%" border="1" align="center">
<tr>
<td><div align="center">1:
<input type="FILE" name="FILE1" size="30">
</div></td>
</tr>
<tr>
<td><div align="center">
<input type="submit" name="Submit" value="上传它!">
</div></td>
</tr>
</table>
</FORM>
</body>
</html>
//处理文件,开始上传
------------------UpLoad.jsp-----------------

<%...@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %>

<%...@ page import="com.jspsmart.upload.*,com.hs.manageimage.exception.ManageImageException"%>
<jsp:useBean id="SU" scope="page" class="com.jspsmart.upload.SmartUpload" />
<html>
<head>
<title>上载附件 </title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<center>

<%...
//上载附件
try
{
out.println(request.getContextPath());
SU.initialize(pageContext); //上传初始化。
//SU.service(request,response);
SU.upload(); //上传文件。
SU.setAllowedFilesList("doc,txt,jpg");// 设定允许上传的文件(通过扩展名限制),仅允许doc,txt文件。
SU.setDeniedFilesList("exe,bat,jsp,htm,html,,"); //设定禁止上传的文件(通过扩展名限制),禁止上传带有exe,bat, jsp,htm,html扩展名的文件和没有扩展名的文件。
SU.setMaxFileSize(10000); // 限制每个上传文件的最大长度。
//SU.setTotalMaxFileSize(20000); // 限制总上传数据的长度。
if(!SU.getFiles().getFile(0).isMissing())
{
out.println(SU.getFiles().getFile(0).getFieldName().toString()+SU.getFiles().getFile(0).getFilePathName().toString()+
SU.getFiles().getFile(0).getFileExt().toString()+
SU.getFiles().getFile(0).getSize()+
SU.getFiles().getFile(0).isMissing());
String fn=SU.getFiles().getFile(0).getFileName(); //获得上传名称
SU.save("uploadDir/");//文件保存的目录为UploadDir
out.println("<br>成功上传,请查看<a href=/manageImage/uploadDir/"+fn+"> uploadDir/"+fn+"文件</a>,<br>确认文件是否上传成功!");
}else
{
response.sendRedirect("./UpLoad.html");
}
}
catch(Exception ex)
{
throw new ManageImageException("上传图片的类型出现错误");
}

%>
<a href=UpLoad.html><div>重新上传文件</div></a>
</body>
</html>
