jspsmartupload组件实现单个或多个文件上传(下)
来源:互联网 发布:知柏地黄丸 编辑:程序博客网 时间:2024/05/17 04:45
///实现添加多个附件
<%@ page language="java" pageEncoding="GBK"%>
<html>
<head>
<title>struts upload by zhangc</title>
<script language="javascript">
var rnum = 1;
function addRow()
{
var oT = document.getElementById("oTable");
var newTR = oT.insertRow(oT.rows.length-1);
newTR.id = "row" + rnum;
var newTD0 = newTR.insertCell();
var newTD1 = newTR.insertCell();
newTD1.setAttribute("colSpan","2");
newTD0.innerText = "file";
newTD1.innerHTML = "<input name=/"file"
+ rnum
+ "/" type=/"file/" > <input name=/"del/" type=/"button/" value=/" del /" onClick=/"deleteRow(" + rnum +");/">";
rnum++;
}
function deleteRow(line)
{
oTable.deleteRow(document.getElementById("row" + line).rowIndex);
}
</script>
</head>
<body>
<form name="updForm" method="post" action="upLoad2.jsp" enctype="multipart/form-data">
<table id="oTable">
<tr>
<td>name</td>
<td><input name="name" type="text"></td>
</tr>
<tr>
<td>files</td>
<td><input type="button" name="add" value=" add " onClick="addRow()"></td>
</tr>
<tr>
<td><input name="sub" type="submit" value=" sub "></td>
</tr>
</table>
</form>
</body>
</html>
///处理上传文件保存到指定路径下
--------------------------------upLoad2.jsp-----------------
<%--
文件名:do_upload.jsp
作 者:纵横软件制作中心雨亦奇(zhsoft88@sohu.com)
--%>
<%@ page contentType="text/html; charset=gb2312" language="java"
import="java.util.*,com.jspsmart.upload.*" errorPage="" %>
<html>
<head>
<title>文件上传处理页面</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<%
// 新建一个SmartUpload对象
SmartUpload su = new SmartUpload();
// 上传初始化
su.initialize(pageContext);
// 设定上传限制
// 1.限制每个上传文件的最大长度。
// su.setMaxFileSize(10000);
// 2.限制总上传数据的长度。
// su.setTotalMaxFileSize(20000);
// 3.设定允许上传的文件(通过扩展名限制),仅允许doc,txt文件。
// su.setAllowedFilesList("doc,txt");
// 4.设定禁止上传的文件(通过扩展名限制),禁止上传带有exe,bat,
//jsp,htm,html扩展名的文件和没有扩展名的文件。
// su.setDeniedFilesList("exe,bat,jsp,htm,html,,");
// 上传文件
su.upload();
// 将上传文件全部保存到指定目录
int count = su.save("/upload");
out.println(count+"个文件上传成功!<br>");
// 利用Request对象获取参数之值
out.println("TEST="+su.getRequest().getParameter("TEST")
+"<BR><BR>");
// 逐一提取上传文件信息,同时可保存文件。
for (int i=0;i<su.getFiles().getCount();i++)
{
com.jspsmart.upload.File file = su.getFiles().getFile(i);
// 若文件不存在则继续
if (file.isMissing()) continue;
// 显示当前文件信息
out.println("<TABLE BORDER=1>");
out.println("<TR><TD>表单项名(FieldName)</TD><TD>"
+ file.getFieldName() + "</TD></TR>");
out.println("<TR><TD>文件长度(Size)</TD><TD>" +
file.getSize() + "</TD></TR>");
out.println("<TR><TD>文件名(FileName)</TD><TD>"
+ file.getFileName() + "</TD></TR>");
out.println("<TR><TD>文件扩展名(FileExt)</TD><TD>"
+ file.getFileExt() + "</TD></TR>");
out.println("<TR><TD>文件全名(FilePathName)</TD><TD>"
+ file.getFilePathName() + "</TD></TR>");
out.println("</TABLE><BR>");
// 将文件另存
// file.saveAs("/upload/" + myFile.getFileName());
// 另存到以WEB应用程序的根目录为文件根目录的目录下
file.saveAs("/upload/" + file.getFileName(), su.SAVE_VIRTUAL);
// 另存到操作系统的根目录为文件根目录的目录下
//file.saveAs("c://temp//" + myFile.getFileName(), su.SAVE_PHYSICAL);
}
%>
</body>
</html>
- jspsmartupload组件实现单个或多个文件上传(下)
- jspsmartupload组件实现单个或多个文件上传(上)
- ajaxfileupload实现单个或多个文件的上传
- Struts2上传单个或多个文件
- android上传单个或多个文件
- java 单个或多个文件上传
- 上传单个或多个文件
- 用jspSmartUpload组件实现文件上传、下载
- spring boot 单个或多个文件上传
- 使用JspSmartUpload组件上传文件
- 文件上传—jspSmartUpload组件
- 理论---jsp使用jspsmartupload组件实现文件上传功能
- jspSmartUpload多文件上传
- 使用commons-fileupload实现单个和多个文件上传
- 使用commons-fileupload实现单个和多个文件上传
- 使用commons-fileupload实现单个和多个文件上传
- 使用commons-fileupload实现单个和多个文件上传
- struts2实现上传文件(单个、多个)
- oracle 回滚段数据文件损坏修复
- IBM开发高速网络技术 每秒传输信息8万比特
- Spring, Hibernate与Struts集成思路
- 3Com重开股东会讨论 华为贝恩资本购3Com现转机
- JavaScript代码(一)
- jspsmartupload组件实现单个或多个文件上传(下)
- 作一个程序员应有的素质
- 3月3日收盘行情
- Windows Thread Synchronization With Kernel Objects
- 对FckEditor编辑器在MAXTHON浏览器下选择服务器文件对话框显示不正常的改进对FckEditor编辑器在MAXTHON浏览器下选择服务器文件对话框显示不正常的改进
- Sun:收购MySQL是现代软件史第一大并购案
- 公司要来督查了!
- 李开复:我大学时对网游也很上瘾
- 条码条形码编程技术泛谈