可以一次上传多个文件
upload.html
<html> <head> <title>网页设计:文件上传</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <body> <p> </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" import="com.jspsmart.upload.SmartUpload" %> <html> <head> <title>中国网页设计:文件上传处理页面</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <body> <% SmartUpload su = new SmartUpload(); su.initialize(pageContext); // 上传初始化 su.upload(); // 上传文件 int count = su.save("/upload"); out.println(count+"个文件上传成功!<p />"); // 逐一提取上传文件信息,同时可保存文件。 for (int i=0;i<su.getFiles().getCount();i++) { com.jspsmart.upload.File file = su.getFiles().getFile(i); // 若文件不存在则继续 if (file.isMissing()) continue; // 显示当前文件信息 out.println("文件长度(Size):" + file.getSize() + "<br />"); out.println("文件名(FileName):" + file.getFileName() + "<br />"); out.println("文件扩展名(FileExt):" + file.getFileExt()); out.print("<br>___________________________<br>"); } %> </body> </html>
125jz网原创文章。发布者:江山如画,转载请注明出处:http://www.125jz.com/2923.html