首先要先下个jspSmartUpload.jar,网上有!下面是我以前写的。你看看吧。
html代码:
<html>
<head>
<title>文件上传</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head><body>
<hr>
<center>
UpLoadfile<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>
jsp代码:
<%@ page contentType="text/html;charset=gb2312" language="java" import="java.sql.*,java.util.*,com.jspsmart.upload.*" errorPage="" %>
<jsp:useBean id="mySmartUpload" 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 {
mySmartUpload.initialize(pageContext);
mySmartUpload.service(request,response);
mySmartUpload.upload();
// String fn=mySmartUpload.getFiles().getFile(0).getFieldName();
com.jspsmart.upload.File file = mySmartUpload.getFiles().getFile(0);
mySmartUpload.save("ITService\\uploadfiles");
out.println ("已经成功上传了文件,请查看<a href=ITService\\uploadfiles\\"+file.getFileName()+">这里</a>,看文件是否上传成功");
//    }
//    catch (Exception ex) {
//     ex.printStackTrace();
//    }
 %>
<a href=FileUpload.html>重新上传</a>
</body>
</html>