关闭

Weblogic7.0使用jspSmartUpload的秘籍

609人阅读 评论(0) 收藏 举报

先到网上下载jspSmartUpload组件压缩包,解压后将com文件夹放到WEB-INF目录下

上传页面 ------(upload.htmlupload.jsp)

upload.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>文件上传</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<p>&nbsp;</p>
<p align="center">上传文件选择</p>
<FORM METHOD="POST" ACTION="do_upload.jsp"
ENCTYPE="multipart/form-data">
<input type="hidden" name="TEST" value="good">
  <table width="75%" border="1" align="center">
    <tr>
      <td><div align="center">1、
          <input type="FILE" name="FILE1" size="30">
        </div></td>
    </tr>
    <tr>
      <td><div align="center">2、
          <input type="FILE" name="FILE2" size="30">
        </div></td>
    </tr>
    <tr>
      <td><div align="center">3、
          <input type="FILE" name="FILE3" size="30">
        </div></td>
    </tr>
    <tr>
      <td><div align="center">4、
          <input type="FILE" name="FILE4" size="30">
        </div></td>
    </tr>
    <tr>
      <td><div align="center">
          <input type="submit" name="Submit" value="上传它!">
        </div></td>
    </tr>
  </table>
</FORM>
</body>
</html>

do_upload.jsp

<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%@ page import="com.jspsmart.upload.*" %>

<%  
  String myFileName = "";
  
     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=getServletConfig().getServletContext().getRealPath("upload");
 out.print(aa);
    String trace=aa+"//"+myFileName;
 out.print(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()); }
   }
   String type=(String)session.getAttribute("type");
  
%>
<form name="form1" method="post" action="add_xuanzeti.jsp">
  <input type="text" name="type" value="<%=type%>">
  <input type="text" name="name" value="<%=myFileName%>">
  <input type="submit" name="Submit" value="¹Ø±Õ" onClick="window.close()">
</form>

下载页面-----(download.html ; download.jsp)

download.html

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<A
                  href=download.jsp?filename=sm.dat>下载</A>    //其中, sm.dat是要下载的文件名
</body>
</html>

 download.jsp

<%@ page
   language="java"
   contentType="text/html; charset=big5"
   pageEncoding="BIG5"
  import="java.util.*, java.io.*, java.net.URLEncoder"
 %>
 <%
   String aa=aa=getServletConfig().getServletContext().getRealPath("upload");
   String filename=request.getParameter("filename");
   String src_fname = aa+"//"+filename;
   String dst_fname = URLEncoder.encode(filename);
   request.setCharacterEncoding("big5");  
   response.setContentType("application/octet-stream; charset=iso-8859-1");
   response.setHeader("Content-disposition", "attachment; filename=/"" + dst_fname + "/""); 
   FileInputStream fis = null;
   int byteRead;
   try {
     fis = new FileInputStream(src_fname);
     while ((byteRead = fis.read()) != -1) {
       out.write(byteRead);
    }
     out.flush();
   }
   catch (Exception e) {
     out.clearBuffer();
    response.setContentType("text/html; charset=big5");
     response.setHeader("Content-disposition", "inline");
     out.println("<HTML><BODY><P>");
     out.println(e.toString());
     out.println("</P></BODY></HTML>");   
  }
   if (fis != null) {
     fis.close();
   }
   return; // 避免下面多按了 Enter 键而输出多余的换行字元.
 %>

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1275次
    • 积分:24
    • 等级:
    • 排名:千里之外
    • 原创:1篇
    • 转载:1篇
    • 译文:0篇
    • 评论:0条
    文章存档