上傳界面FileUpload.html
<html>
<head>
<title>上傳</title>
</head>
<body>
<hr>
<center>
upload file<br>
<form action="upload.jsp" method="post" enctype="multipart/form-data">
<table><tr><td>name:
<input type="file" name="file" size="20"></td></tr>
<tr><td><input type="submit" value="上傳"></td></tr>
</table>
</form>
<center>
</body>
</html>
保存上傳文件 upload.jsp
<%@ page contentType="text/html;charset=gb2312" language="java"%>
<%@ page import="com.jspsmart.upload.*,java.sql.*"%>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload"/>
<html>
<head><title>上載附件</title></head>
<body>
<center>正在上傳文件....
<%
try {
mySmartUpload.initialize(pageContext);
mySmartUpload.service(request,response);
mySmartUpload.upload();
String fn=mySmartUpload.getFiles().getFile(0).getFileName();
mySmartUpload.save("upload/");
out.println("已經上傳了文件,請查看<a href=upload/"+fn+">這裏</a>,看文件是否上傳成功");
}catch(Exception e) {
e.printStackTrace();}
%>
<a href=FileUpload.html>重新上傳</a>
</body>
</html>