Struts---多文件上传、单文件下载
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd"> <struts>
<constant name="struts.multipart.maxSize" value="3000000001000"></constant>
<package name="a" extends="struts-default"> <!-- 上传 多文件上传 -->
<action name="upload" class="com.zr.fileupload" method="upload">
<param name="allowedTypes">image/bmp,image.jpg</param>
<param name="allowedExtensions">.jpg</param>
<interceptor-ref name="fileUpload">
<param name="maximumSize">81111110111</param>
</interceptor-ref>
<interceptor-ref name="defaultStack"/>
<result name="OK">/upload.jsp</result>
</action> <!-- 下载 单文件下载 -->
<action name="DownLoad" class="com.zr.DownLoad">
<result type="stream">
<param name="contentDisposition">attachment;filename=${fileName}</param>
</result> </action>
</package>
</struts>
下载方法
package com.zr; import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException; import com.opensymphony.xwork2.ActionSupport; public class DownLoad extends ActionSupport{ private String fileName; public String getFileName() throws Exception{
fileName=new String(fileName.getBytes(), "ISO8859-1");
return fileName;
} public void setFileName(String fileName) {
this.fileName = fileName;
} public InputStream getInputStream()throws Exception{
File file=new File("C:/jdk-6u39-windows-i586.exe");
this.fileName="jdk-6u39-windows-i586.exe";
return new FileInputStream(file);
} }
实体类
package com.zr; import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import com.opensymphony.xwork2.ActionSupport;
public class fileupload extends ActionSupport{ private File [] upload;
private String [] uploadFileName;
private String [] uploadContentType; public String upload() throws IOException{
for (int i = 0; i <upload.length; i++) {
String filepath="c:/"+uploadFileName[i];
File fp=new File(filepath);
FileUtils.copyFile(upload[i], fp);
}
return "OK";
} public File[] getUpload() {
return upload;
}
public void setUpload(File[] upload) {
this.upload = upload;
}
public String[] getUploadFileName() {
return uploadFileName;
}
public void setUploadFileName(String[] uploadFileName) {
this.uploadFileName = uploadFileName;
}
public String[] getUploadContentType() {
return uploadContentType;
}
public void setUploadContentType(String[] uploadContentType) {
this.uploadContentType = uploadContentType;
}
}
index.jsp页面
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<SCRIPT type="text/javascript" src="jquery-1.8.2.min.js"></SCRIPT>
</head>
<body>
<embed
name="honehoneclock"
width="320"
align="middle"
pluginspage="http://www.macromedia.com/go/getflashplayer"
src="http://chabudai.sakura.ne.jp/blogparts/honehoneclock/honehone_clock_wh.swf"
type="application/x-shockwave-flash"
allowscriptaccess="always"
bgcolor="#ffffff"
quality="high"
wmode="transparent"
> <form action="upload" method="post" enctype="multipart/form-data">
<input type="file" name="upload"><br/>
<input type="file" name="upload"><br/>
<input type="file" name="upload"><br/>
<input type="submit" value="上传"> <br/>
</form> <a href="DownLoad.action">下载</a> </body>
</html>
struts配置注意事件

以上内容为个人笔记记录
可供他人参考
2017-08-1112:51:01
Struts---多文件上传、单文件下载的更多相关文章
- 分享知识-快乐自己:SpringMvc中的单多文件上传及文件下载
摘要:SpringMvc中的单多文件上传及文件下载:(以下是核心代码(拿过去直接能用)不谢) <!--设置文件上传需要的jar--> <dependency> <grou ...
- Struts的文件上传下载
Struts的文件上传下载 1.文件上传 Struts2的文件上传也是使用fileUpload的组件,这个组默认是集合在框架里面的.且是使用拦截器:<interceptor name=" ...
- struts2中的文件上传,文件下载
文件上传: Servlet中的文件上传回顾 前台页面 1.提交方式post 2.表单类型 multipart/form-data 3.input type=file 表单输入项 后台 apache提交 ...
- struts2的文件上传和文件下载
实现使用Struts2文件上传和文件下载: 注意点: (1)对应表单的file1和私有成员变量的名称必须一致 <input type="file" name="fi ...
- struts 多文件上传 annotation注解(零配置)+ ajaxfileupload + 异步 版本
[本文简介] struts 多文件上传.基于”零配置“+"ajaxfileupload" 的一个简单例子. [导入依赖jar包] jquery-1.7.2.js : http:// ...
- struts 多文件上传 xml 版本
[本文简介] 本文将介绍 以配置 struts.xml 的方式 实现 多文件上传的功能. [文件夹结构] [struts.xml] <?xml version="1.0" ...
- struts文件上传、文件下载
文件上传 如果在表单中上传文件,表单的enctype属性为multipart/form-data struts默认上传文件大小为2M,如果需要修改,在配置文件中设置 <constant name ...
- struts2实现文件上传、多文件上传和文件下载
总结的两个问题,就是struts2上传下载的时候对属性名配置要求非常严格: 第一:上传的时候 private File file; private String fileContentType; pr ...
- java框架篇---struts之文件上传和下载
Struts2文件上传 Struts 2框架提供了内置支持处理文件上传使用基于HTML表单的文件上传.上传一个文件时,它通常会被存储在一个临时目录中,他们应该由Action类进行处理或移动到一个永久的 ...
- struts2中的文件上传和文件下载
单文件文件上传 1.
随机推荐
- Kay and Snowflake CodeForces - 686D (树的重心性质)
After the piece of a devilish mirror hit the Kay's eye, he is no longer interested in the beauty of ...
- Adaptive Synchronization of Dynamics on Evolving Complex Networks
原文链接:https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.100.114101 发表在:PRL 2008 ------------- ...
- session共享原理以及PHP 实现多网站共享用户SESSION 数据解决方案
参考自: http://www.cnblogs.com/qulinke/articles/6003049.html https://segmentfault.com/q/101000000578847 ...
- poi导出excel数据量过大
问题:使用poi导出excel,数据量过大导致内存溢出 解决思路:1.多sheet导出 2.生成多个excel打包下载 3.生成csv下载 本文使用的是第二个思路,代码如下: poiUtil工具类 p ...
- [uboot] (番外篇)uboot之fdt介绍 (转)
以下例子都以project X项目tiny210(s5pv210平台,armv7架构)为例 [uboot] uboot流程系列:[project X] tiny210(s5pv210)上电启动流程(B ...
- Liunx centos 系统 修改hostname
1 centos6下修改hostname [root@centos6 ~]$ hostname # 查看当前的hostnmae centos6.magedu.com [root@centos6 ~]$ ...
- 清空DataGridView
DataTable dt = (DataTable)dgv.DataSource; dt.Rows.Clear(); dgv.DataSource = dt;
- [RCTF]Pwn200 wp
0x00: XCTF开赛了,只看了pwn,这次还比较有意思,有x86 x64 arm mips 多种cpu构架的pwn.自己只搞出了pwn200 0x01: 基本信息: x64 动态链接 有调试符 ...
- #415 Div2 Problem C Do you want a data? (math && 前后缀和 && 快速幂)
题意: 首先定义集合的F值为 这个集合里面最大值和最小值的差. 现给出一个拥有n个数的集合(没有相同的元素), 要求求出这个集合内所有子集的F的值的和.例如: {4.7}这个集合里面有子集{4}.{ ...
- 学习笔记:python3,代码。小例子习作
http://www.cnblogs.com/qq21270/p/7634025.html 学习笔记:python3,一些基本语句(一些基础语法的代码,被挪到这里了) 日期和时间操作 http://b ...