日期:2014-05-18  浏览次数:20626 次

100分,求JSP上传EXCEL文件代码,可以弹出文件选择框,并限制选择文件只能是1.xls!
100分,求JSP上传EXCEL文件代码,可以弹出文件选择框,并限制选择文件只能是1.xls!


请各位赐教!

------解决方案--------------------
File f1=new File( "J:\\Tomcat 5.5\\webapps\\ROOT\\test ",tempfilename);


tempfilename 改成你想设的文件名,试试吧
------解决方案--------------------
前两天我写的一个上传图片的jsp,本来是一个读取excel的jsp
也是东拼西凑,希望能给你帮助

<%@ page contentType= "text/html; charset=GB2312 " %>
<%@page import= "java.util.* "%>
<%@page import= "java.util.Date "%>
<%@page import= "java.sql.* "%>
<%@page import= "javax.sql.* "%>
<%@page import= "sun.jdbc.rowset.* "%>
<%@page import= "java.io.* "%>
<%@page import= "javax.servlet.* "%>
<%@page import= "org.gqforce.* "%>
<%@page import= "javax.servlet.http.*,com.jspsmart.upload.*,jxl.* "%>
<%
String conPath=request.getContextPath();
%>
<html>
<SCRIPT LANGUAGE= "JavaScript " src= " <%=conPath%> /js/common.js "> </SCRIPT>
<SCRIPT LANGUAGE= "JavaScript " src= " <%=conPath%> /js/translate.js "> </SCRIPT>
<script>
function showimg()
{
document.Myform.Myimg.src=document.Myform.filename.value;
}
function checkinput()
{
var strFileFormat = form1.file.value.match(/^(.*)(\.)(.{1,8})$/)[3];//检查上传文件格式
if(strFileFormat== "jpg "||strFileFormat== "gif "||strFileFormat== "jpeg "||strFileFormat== "bmp "||strFileFormat== "JPG "||strFileFormat== "GIF "||strFileFormat== "JPEG "||strFileFormat== "BMP ") //用js方法限制上传类型,其实可以用upper()方法优化
{
return true;
}
else
{
alert( "只能上传.bmp,.jpg,jpeg和.gif,请重新选择! ");
return false;
}

}

</script>
<form method= "post " enctype= "multipart/form-data " name= "form1 " action = ' '>
<table border= "0 " cellspacing= "0 " cellpadding= "0 " align= "center " width= "100% " >
<tr>
<td>
<table width= "90% " id= "uploadTable " border= "0 " height= "100% " cellspacing= "0 " cellpadding= "0 " align= "center ">
<tr>
<td align= "center " height= "27 ">
<input type= "file " name= "file " class= "inputfile " id= "fileInput " style= "width:210 " required = "true " msg= "上传文件 ">
<!-- <input type= "button " name= "Submit " value= "+ " onclick= "addSelfRow() "> -->
</td> <td> <input type= 'button ' onclick= "checkinput();submit(); " value= '提交 '> </td>
</tr>
</table>
</td>
</tr> </table>
</form>
</html>
<%
String path=request.getContextPath();
com.jspsmart.upload.SmartUpload smartUpload=new com.jspsmart.upload.SmartUpload();

smartUpload.initialize(pageContext);
String fileName= " ",fileNameStr= " ";