<%@ page import="java.sql.*"%>  
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.text.*"%>
<%@ page import="java.util.*"%>
<%@ page import="db.*"%>
<%@ page import="jxl.*"%>
<%@ page language="java" import="com.jspsmart.upload.*"%>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=UTF-8 ">  
<title> 文件上传处理页面</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body class="main-body">
<div class="main-bar">
当前位置: <a href="#">层次目录一</a> &raquo; <a href="#">层次目录二</a>
</div>
<div class="main-wrapper cf">
<div class="jc-bg">
<%  
 try
{
// 新建一个SmartUpload对象  
SmartUpload su = new SmartUpload();  
// 上传初始化  
su.initialize(pageContext);  
// 设定上传限制  
// 1.限制每个上传文件的最大长度。  
// su.setMaxFileSize(10000);  
// 2.限制总上传数据的长度。  
// su.setTotalMaxFileSize(20000);  
// 3.设定允许上传的文件(通过扩展名限制),仅允许doc,txt文件。  
// su.setAllowedFilesList( "doc,txt ");  
// 4.设定禁止上传的文件(通过扩展名限制),禁止上传带有exe,bat,jsp,htm,html扩展名的文件和没有扩展名的文件。  
// su.setDeniedFilesList( "exe,bat,jsp,htm,html,, ");  
// 上传文件  
su.upload();  
// 将上传文件全部保存到指定目录  
 su.save( "upload");  
out.println("文件上传成功! <br/> ");  // 利用Request对象获取参数之值  
out.println( "TEST= "+su.getRequest().getParameter( "TEST ") +" <BR> <BR> ");  // 逐一提取上传文件信息,同时可保存文件。  for (int i=0;i <su.getFiles().getCount();i++)  
{  
com.jspsmart.upload.File file = su.getFiles().getFile(i);  // 若文件不存在则继续  
if (file.isMissing()) continue;  
String path1=new String(file.getFilePathName().getBytes("GBK"), "ISO-8859-1");  
// 显示当前文件信息  
out.println( " <TABLE BORDER=1> ");  
out.println( " <TR> <TD> 表单项名(FieldName) </TD> <TD> " + new String(file.getFieldName().getBytes("GBK"), "ISO-8859-1") + " </TD> </TR> ");  
out.println( " <TR> <TD> 文件长度(Size) </TD> <TD> " + file.getSize() + " </TD> </TR> ");  
out.println( " <TR> <TD> 文件名(FileName) </TD> <TD> " + new String(file.getFileName().getBytes("GBK"), "ISO-8859-1") + " </TD> </TR> ");  
out.println( " <TR> <TD> 文件扩展名(FileExt) </TD> <TD> " + file.getFileExt() + " </TD> </TR> ");  
out.println( " <TR> <TD> 文件全名(FilePathName) </TD> <TD> " + path1 + " </TD> </TR> ");  
out.println( " </TABLE> <BR> ");  
//su.SAVE_PHYSICAL();   String path="/upload/ceshi.xls";
 file.saveAs(path);String paths="D:\\http\\cxbackground\\upload\\ceshi.xls";String fileName=""; java.io.File newFile = new File(paths);   Workbook workbook = Workbook.getWorkbook(newFile);  
  Sheet sheet = workbook.getSheet(0);  
  int rows=sheet.getRows();  
  CONN conn;
conn= new CONN();
Connection databaseConnection=conn.databaseConnection;
Statement St = databaseConnection.createStatement();
ResultSet rst;
String sql;   
    
  for(int j=1;j <rows;j++){   
  String id=sheet.getCell(1,j).getContents();  
  String cpid=sheet.getCell(2,j).getContents();  
  String wfxw=sheet.getCell(3,j).getContents();  
  out.print(id);
  out.print(cpid);
  out.print(wfxw);
  sql="insert into TD_CXcity_wfmassage(userid,cpid,wfxw)values('"+id+"','"+cpid+"','"+wfxw+"')";  
  St.executeUpdate(sql);  
  System.out.println(sql);  
  }  
}
}
catch (SQLException sqle)
{
System.err.println(sqle);
}%>  </div>
</div>
</body>
</html>

解决方案 »

  1.   

    org.apache.jasper.JasperException: Unable to compile class for JSP:  An error occurred at line: 81 in the jsp file: /upload.jsp
    The type File is ambiguous
    78:  
    79:  
    80:  
    81: java.io.File newFile = new File(paths);  
    82:  
    83: Workbook workbook = Workbook.getWorkbook(newFile);  
    84: Sheet sheet = workbook.getSheet(0);  
    不知道怎么出的错~ 大家帮帮忙哇!!!!!!
      

  2.   

    [code]
    java.io.File newFile = new File(paths); 改成File newFile = new File(paths); 试试你jsp头已经导入了io包了。。不需要再加一个java.io.File,报错为类型模糊。[/code]
      

  3.   

    改为File newFile = new File(paths); 不行。java.io.File newFile = new java.io.File(paths); 这样可以~。~谢谢了终于出来了~