webwork2中多文件上传的处理
来源:互联网 发布:54转80坐标软件 编辑:程序博客网 时间:2024/06/06 01:50
webwork2中多文件上传的处理 作者:onebody(onebodysoftware@hotmail.com)
1. webwork-default.xml 配置 (拦截器的配置)
<interceptors>
<interceptor name="fileUpload" class="com.opensymphony.webwork.interceptor.FileUploadInterceptor"/>
<!-- Sample file upload stack -->
<interceptor-stack name="fileUploadStack">
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="basicStack"/>
</interceptor-stack>
</interceptors>
<interceptor name="fileUpload" class="com.opensymphony.webwork.interceptor.FileUploadInterceptor"/>
<!-- Sample file upload stack -->
<interceptor-stack name="fileUploadStack">
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="basicStack"/>
</interceptor-stack>
</interceptors>
2. xwork.xml 配置 (处理的Action配置)
<package name="fileUpload" namespace="fileUpload" extends="webwork-default">
<action name="fileUpload" class="com.omyos.fileUpload.UploadAction">
<result name="main">fileUploadIndex.jsp</result>
<interceptor-ref name="fileUpload"/>
</action>
</package>
<action name="fileUpload" class="com.omyos.fileUpload.UploadAction">
<result name="main">fileUploadIndex.jsp</result>
<interceptor-ref name="fileUpload"/>
</action>
</package>
3. webwork.properties 配置
/*多文件上传 单个文件上传时直接用pell就行了
单文件与多文件上传的处理有所不同详细Action类中的描述*/
webwork.multipart.parser=jakarta
3. fileUploadIndex.jsp 代码
<html>
<head><title>多文件上传实例</title></head>
<script language="Javascript" charset="utf-8">
function addAccessory() ...{
var accessoryListObj = document.getElementById("accessoryList");
var accObj = document.createElement("span");
var spanId = (new Date()).getTime();
var spanHTML = " <input name=files type=file width=100px/><input type=button value=删除 onclick=deleteFile('" + spanId + "')><br>";
accObj.setAttribute("id", spanId);
accObj.setAttribute("width", "100px");
accObj.innerHTML = spanHTML;
accessoryListObj.appendChild(accObj);
}
function deleteFile(fileId) ...{
var accessoryListObj = document.getElementById("accessoryList");
var accObj = document.getElementById(fileId);
accessoryListObj.removeChild(accObj);
}
</script>
<body>
<form action="fileUpload/fileUpload.action" enctype="multipart/form-data" method="post">
<table id="DataTable">
<tbody>
<tr>
<td class="style2" colspan="4"><strong>附件: </strong>
<span title="增加附件"
onclick="addAccessory()"
style="cursor:pointer;color:blue;"><strong>[添加附件]</strong></span>
</td>
</tr>
<tr>
<td colspan="4" style="width:100%;height:300px;">
<div id="accessoryList"
style="overflow-x:hidden;overflow-y:auto;width:100%;height:100%;">
</div>
</td>
</tr>
<tr>
<td colspan="4" style="width:100%;height:15px;" align="center">
<input type="Submit" name="提交">
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
<head><title>多文件上传实例</title></head>
<script language="Javascript" charset="utf-8">
function addAccessory() ...{
var accessoryListObj = document.getElementById("accessoryList");
var accObj = document.createElement("span");
var spanId = (new Date()).getTime();
var spanHTML = " <input name=files type=file width=100px/><input type=button value=删除 onclick=deleteFile('" + spanId + "')><br>";
accObj.setAttribute("id", spanId);
accObj.setAttribute("width", "100px");
accObj.innerHTML = spanHTML;
accessoryListObj.appendChild(accObj);
}
function deleteFile(fileId) ...{
var accessoryListObj = document.getElementById("accessoryList");
var accObj = document.getElementById(fileId);
accessoryListObj.removeChild(accObj);
}
</script>
<body>
<form action="fileUpload/fileUpload.action" enctype="multipart/form-data" method="post">
<table id="DataTable">
<tbody>
<tr>
<td class="style2" colspan="4"><strong>附件: </strong>
<span title="增加附件"
onclick="addAccessory()"
style="cursor:pointer;color:blue;"><strong>[添加附件]</strong></span>
</td>
</tr>
<tr>
<td colspan="4" style="width:100%;height:300px;">
<div id="accessoryList"
style="overflow-x:hidden;overflow-y:auto;width:100%;height:100%;">
</div>
</td>
</tr>
<tr>
<td colspan="4" style="width:100%;height:15px;" align="center">
<input type="Submit" name="提交">
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
4.com.omyos.fileUpload.UploadAction.java 代码
public class DataInfoAction extends ActionSupport...{
private File[] files; //多个文件对象数组
private String[] filesFileName; //文件对应的真实文件名 单个文件上传时不需要此属性定义
//多文件上传时 file.getName() 无效,取得不是真实的文件名,而是upload_xxx.tmp
public String execute() ...{
if (files != null) ...{
for (int i = 0; i < files.length; i++) ...{
File file = files[i];
String fileName = filesFileName[i];
System.out.print(" File list: ");
System.out.print(" name:=" + file.getName() + " ");
System.out.print(" fileName:=" + fileName + " ");
System.out.print(" path:=" + file.getPath() + " ");
System.out.print(" ");
//文件上传的代码自己code吧...
}
}
return SUCCESS;
}
public String[] getFilesFileName() ...{
return filesFileName;
}
public void setFilesFileName(String[] filesFileName) ...{
this.filesFileName = filesFileName;
}
public File[] getFiles() ...{
return files;
}
public void setFiles(File[] files) ...{
this.files = files;
}
/**//**
* 获取session对象
* @return
*/
public HttpSession getSession() ...{
return getRequest().getSession();
}
/**//**
* 获取request对象
*
* @return httpServletRequest
*/
public HttpServletRequest getRequest() ...{
return ServletActionContext.getRequest();
}
/**//**
* 获取response对象
*
* @return HttpServletResponse
*/
public HttpServletResponse getResponse() ...{
return ServletActionContext.getResponse();
}
/**//**
* 获取ServletContext对象
*
* @return ServletContext
*/
public ServletContext getContext() ...{
return ServletActionContext.getServletContext();
}
/**//**
* 获取ActionContext
*
* @return
*/
public ActionContext getActionContext() ...{
return ActionContext.getContext();
}
/**//**
* 获取参数map
*
* @return
*/
public Map getParameterMap() ...{
return getActionContext().getSession();
}
/**//**
* 获取输入参数名字对应的值
*
* @param name
* @return
*/
public String getParameter(String name) ...{
return (String) getParameterMap().get(name);
}
}
private File[] files; //多个文件对象数组
private String[] filesFileName; //文件对应的真实文件名 单个文件上传时不需要此属性定义
//多文件上传时 file.getName() 无效,取得不是真实的文件名,而是upload_xxx.tmp
public String execute() ...{
if (files != null) ...{
for (int i = 0; i < files.length; i++) ...{
File file = files[i];
String fileName = filesFileName[i];
System.out.print(" File list: ");
System.out.print(" name:=" + file.getName() + " ");
System.out.print(" fileName:=" + fileName + " ");
System.out.print(" path:=" + file.getPath() + " ");
System.out.print(" ");
//文件上传的代码自己code吧...
}
}
return SUCCESS;
}
public String[] getFilesFileName() ...{
return filesFileName;
}
public void setFilesFileName(String[] filesFileName) ...{
this.filesFileName = filesFileName;
}
public File[] getFiles() ...{
return files;
}
public void setFiles(File[] files) ...{
this.files = files;
}
/**//**
* 获取session对象
* @return
*/
public HttpSession getSession() ...{
return getRequest().getSession();
}
/**//**
* 获取request对象
*
* @return httpServletRequest
*/
public HttpServletRequest getRequest() ...{
return ServletActionContext.getRequest();
}
/**//**
* 获取response对象
*
* @return HttpServletResponse
*/
public HttpServletResponse getResponse() ...{
return ServletActionContext.getResponse();
}
/**//**
* 获取ServletContext对象
*
* @return ServletContext
*/
public ServletContext getContext() ...{
return ServletActionContext.getServletContext();
}
/**//**
* 获取ActionContext
*
* @return
*/
public ActionContext getActionContext() ...{
return ActionContext.getContext();
}
/**//**
* 获取参数map
*
* @return
*/
public Map getParameterMap() ...{
return getActionContext().getSession();
}
/**//**
* 获取输入参数名字对应的值
*
* @param name
* @return
*/
public String getParameter(String name) ...{
return (String) getParameterMap().get(name);
}
}
- webwork2中多文件上传的处理
- struts2中多文件上传的处理
- Struts2中处理文件上传
- jsp文件上传的处理
- 上传文件的路径处理
- jsp文件上传的处理
- 上传文件的处理细节
- 上传文件的处理细节
- smartupload处理文件的上传
- anjularjs的处理文件上传
- 多文件上传处理页面
- 上传文件的处理细节、文件下载
- ASP.NET多文件上传的处理方式
- Java 多文件上传存储到不同的路径及某上传框中未选择上传文件的处理方法
- WebWork2.2中结合Spring:新的方式
- AJAX应用:巧妙的处理文件上传
- 手工处理 Struts2 框架上传的文件
- 手工处理 Struts2 框架上传的文件
- 公司笔试c、c++试题
- ACCESS大批量数据写入之性能提升方案
- 软件开发中关注习惯的力量
- 在Delphi中开发使用多显示器的应用程序
- 自动化测试框架:日志的分析
- webwork2中多文件上传的处理
- SilverLight是什么?
- 一点念头
- 性能设计中的平衡-提防物极必反
- 密码破解极限覆盖范围浅析 (ALLyeSNO)
- 程序员,你双屏了吗?
- 自动化测试框架:拥抱Ruby
- 配置C-JDBC(Sequoia)(MS SQLSERVER+Orace)
- 伯乐很多,你是千里马吗?