提交页面:FileUpload.jsp
<html>
<SCRIPT>
function submit1()
{
if(form1.file.value.length==0){
alert( "请选择文件 ");
form1.file.focus;
return false;
}
}
</SCRIPT>
<head>
<title> 上传 </title>
</head>
<body>
<hr>
<form action= "upload.jsp " method= "post " name = "form1 " enctype= "multipart/form-data ">
<div align= "left ">
<table width= "401 "> <tr> <td>
<font size= "2 "> Excel </font> :
<input type= "file " name= "file " size= "20 "> <input type= "submit " value= "上传 " onclick = "submit1() "> </td> </tr>
<tr> <td> </td> </tr>
</table>
</div>
</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>
<%
try {
mySmartUpload.initialize(pageContext);
mySmartUpload.service(request,response);
mySmartUpload.upload();
String fn=mySmartUpload.getFiles().getFile(0).getFileName();
mySmartUpload.save( "E:/Tomcat 5.0/webapps/rs/upload ");
}catch(Exception e) {
e.printStackTrace();}
%>
</body>
</html>
-----------------------------------------------------
问题:
1、如果准备上传的文件名是aa.xls,上传后如何成为bb.xls;
2、如何限制上传文件大小,比如不能大于2M;
3、如何限制用户只能上传excel文件?
请赐教,根据以上问题,应该如何修改代码?
------解决方案--------------------
1、设置保存文件的文件名
file.saveAs(savePath + file.getFileName());