⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 do_upload.jsp

📁 用jsp编写的文件上传与下载系统。(1)先将com目录拷贝到webappsROOTWEB-INFclasses下
💻 JSP
字号:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%@ page import="com.jspsmart.upload.*" %>

<%   //Integer ii=(Integer)session.getAttribute("filename");
    // int filename=ii.intValue();
	// int filename1=filename+1;
	// session.setAttribute("filename",new Integer(filename1));
   //  System.out.println((((Integer)session.getAttribute("filename")).intValue()));
	 String myFileName = "";
   //实例化上载bean
     com.jspsmart.upload.SmartUpload mySmartUpload=new com.jspsmart.upload.SmartUpload();
    //初始化
     mySmartUpload.initialize(pageContext); 
    //设置上载的最大值
    mySmartUpload.setMaxFileSize(500*1024*1024);
    //上载文件
    mySmartUpload.upload();
   //循环取得所有上载的文件
   for (int i=0;i<mySmartUpload.getFiles().getCount();i++){
   //取得上载的文件
   com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);
   if (!myFile.isMissing())
    {
   //取得上载的文件的文件名
    myFileName=myFile.getFileName();
    //取得不带后缀的文件名
    String  suffix=myFileName.substring(0,myFileName.lastIndexOf('.'));
    //取得后缀名
    String  ext= mySmartUpload.getFiles().getFile(0).getFileExt();  
    //取得文件的大小  
    int fileSize=myFile.getSize();
    //保存路径
    String aa=getServletContext().getRealPath("/")+"upload\\";
    String trace=aa+myFileName;
	//System.out.println(trace);
    //取得别的参数
    String explain=(String)mySmartUpload.getRequest().getParameter("text");
    String send=(String)mySmartUpload.getRequest().getParameter("send");
    //将文件保存在服务器端 
    myFile.saveAs(trace,mySmartUpload.SAVE_PHYSICAL);
    //下面的是将上载的文件保存到数据库中
    //将文件读到流中 
 
   out.println(("上载成功!!!").toString());
   }
   else 
   { out.println(("上载失败!!!").toString()); } 
   }//与前面的if对应
   String type=(String)session.getAttribute("type");
   //System.out.println(type);
%>
<form name="form1" method="post" action="add_xuanzeti.jsp">
  <input type="hidden" name="type" value="<%=type%>">
  <input type="hidden" name="name" value="<%=myFileName%>">
  <input type="submit" name="Submit" value="关闭" onClick="window.close()">
</form>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -