<%@ page contentType="text/html; charset=gb2312" language="java" 
import="java.util.*,com.jspsmart.upload.*,java.sql.*"  %>
<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>
<%

try{
     mySmartUpload.initialize(pageContext);
     mySmartUpload.service(request,response);

     mySmartUpload.setMaxFileSize(10000);
 
     mySmartUpload.setTotalMaxFileSize(30000);

     mySmartUpload.setAllowedFilesList("doc,txt");
     mySmartUpload.setDeniedFilesList("exe,jsp,bat,htm,html,");

     mySmartUpload.upload();

 


          String  DBDriver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
          Class.forName(DBDriver);
          String Con="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=yjs";
          String username="bn";
          String pwd="bn";
          Connection con=DriverManager.getConnection(ConStr,username,pwd);
          Statement stmt=con.createStatement(); 
          com.jspsmart.upload.File file1 = mySmartUpload.getFiles().getFile(0);
          com.jspsmart.upload.File file2 = mySmartUpload.getFiles().getFile(1);
          com.jspsmart.upload.File file3 = mySmartUpload.getFiles().getFile(2);
      
          String fileupload1 = file.getFileName();
          String fileupload2 = file.getFileName();
          String fileupload3 = file.getFileName();
       
           String  sql = "select filename from fileinfo where studentid='"+123+"' and (filename='"+fileupload1+"' or filename='"+fileupload2+"'  or filename='"+fileupload3+"') ";
   ResultSet rst = stmt.executeQuery(sql);
   
  if(rst.next()) {out.println("您上传的文件中至少有一个和以前上传过的文件重名,为了避免覆盖以前的文件请更改一下附件的名字");return;}
  

 for (int i=0;i<mySmartUpload.getFiles().getCount();i++){
  com.jspsmart.upload.File file = mySmartUpload.getFiles().getFile(i);
  if(file.isMissing()) continue;// 若文件不存在则继续   file.getFieldName();
  file.getSize();
  file.getFileName();
  file.getFileExt();
  file.getFilePathName();   String filename = file.getFileName();
  int  filesize = file.getSize();
  String fileext = file.getFileExt();
        
String sql1 = "insert into fileinfo filename,filesize.fileext,studentid values ('"+filename+"','"+filesize+"','"+fileext+"','"+123+"')";
stmt.executeUpdate(sql);
   }
response.sendRedirect("shangchuan.jsp");//实现页面跳转
        
}
catch(Exception e){
  e.printStackTrace();
}
%>
</body>
</html>