jspSmartUpload


下载:
/Files/hijackwust/jsmartcom_zh_CN.rar
-----------------------------------------------测试代码 ,三个文件。
jsp页面:
<%@ page contentType="text/html;charset=GBK"%>
<html>
<head>
<title>File Upload</title>
</head>
<body>
<font size=5 color=#FF0000> <b>文件上传----使用jspsmartupload组件</b> </font>
<br>

<form action="uploadfile" method="post"enctype="multipart/form-data">
<p>文件名称: <input type="file" name="file1"size="20" maxlength="80">
</p>
<p>文件名称: <input type="file" name="file2"size="20" maxlength="80">
</p>
<p>文件名称: <input type="file" name="file3"size="20" maxlength="80">
</p>
<p>上传路径: <input type="text" name="path" size="30"maxlength="50"><br>
</p>

<p>附加内容: <input type="text" name="other"size="30" maxlength="50">
</p>
<p><input type="submit" value="上传"><input type="reset"
 value="重置"></p>
</form>

<font size=5 color=#FF0000> <b>文件下载----使用jspsmartupload组件</b> </font>
<br>
<form action="downloadfile" method="post">
<p>下载文件的名称: <input type="text" name="downloadFileName"size="20"
 maxlength="80"></p>
<input type="submit" value="下载">
</body>
</form>
</html>

两个Servlet: ServletUpload 和ServletDownload

public class ServletUpload extends HttpServlet {
 private ServletConfig config;

 final public void init(ServletConfig config) throws ServletException{
  this.config = config;
 }
 protected void doGet(HttpServletRequest request,
   HttpServletResponse response) throws ServletException,IOException {
  // TODO Auto-generated method stub
  PrintWriter out = response.getWriter();
  out.println("<HTML>");
  out.println("<BODY BGCOLOR='white'>");
  out.println("<H1>jspSmartUpload : ServletSample</H1>");
  out.println("<HR>");
  // 变量定义
  int count = 0;
  SmartUpload mySmartUpload = new SmartUpload();
  try {
   mySmartUpload.initialize(config, request, response);
   mySmartUpload.upload();
   for (int i = 0; i < mySmartUpload.getFiles().getCount();i++) {
    com.jspsmart.upload.File myfile =mySmartUpload.getFiles().getFile(i);
    String fileName = myfile.getFileName();
    count = mySmartUpload.save("/upload");
    //count = mySmartUpload.save(null);
   }
   out.println(count + " file uploaded.");
  } catch (Exception e) {
   out.println("Unable to upload thefile.<br>");
   out.println("Error : " + e.toString());
  }
  out.println("</BODY>");
  out.println("</HTML>");
 }
 protected void doPost(HttpServletRequest request,
   HttpServletResponse response) throws ServletException,IOException {
  // TODO Auto-generated method stub
  doGet(request, response);
 }
}

=============================================
public class ServletDownload extends HttpServlet {
 private ServletConfig config;
 final public void init(ServletConfig config) throws ServletException {
  this.config = config;
 }
 protected void doGet(HttpServletRequest request,
   HttpServletResponse response) throws ServletException,IOException {
  String temp_p =request.getParameter("downloadFileName");
  byte[] temp_t=temp_p.getBytes("ISO8859_1");
  String fileName=new String(temp_t,"GBK");
  SmartUpload mySmartUpload = new SmartUpload();
  try {
   mySmartUpload.initialize(config, request, response);
   mySmartUpload.setContentDisposition(null);
   mySmartUpload.downloadFile("/upload/"+fileName);
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
 protected void doPost(HttpServletRequest request,
   HttpServletResponse response) throws ServletException,IOException {
  // TODO Auto-generated method stub
  doGet(request, response);
 }
}

 

转载于:https://www.cnblogs.com/liaoshiyong/p/3150824.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值