Struts2做下载
1、编写anction,如下:
package cn.com.css.misps.onlinegraph.web.action;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import cn.com.css.common.action.BaseAction;
import cn.com.css.misps.domain.ServiceCode;
import cn.com.css.misps.domain.ServiceProductCode;
import cn.com.css.misps.domain.TPrCategory;
import cn.com.css.misps.onlinegraph.service.IServiceCodeService;
import cn.com.css.misps.onlinegraph.service.IServiceProductCodeService;
import cn.com.css.misps.onlinegraph.service.ITPrCategoryService;
import cn.com.css.misps.onlinegraph.service.ITProductInfoService;
import cn.com.css.misps.onlinegraph.util.AnalysisMicaps2BytesUtils;
import cn.com.css.misps.onlinegraph.util.DateUtil;
import cn.com.css.misps.onlinegraph.util.FNameUtils;
import cn.com.css.misps.onlinegraph.util.ImageBytesAnalysisUtils;
import cn.com.css.misps.onlinegraph.util.ProductsStorageUtils;
import cn.com.css.misps.onlinegraph.webservice.impl.GraphWebServiceImpl;
import cn.com.system.domain.Account;
import com.opensymphony.xwork2.ActionContext;
/**
* @brief OnlineGraphAction.java 这里是在线出图部分的代码
* @attention 要注意的是页面中的表单填写的是服务方法中要求填写的参数
* @author 涂作权
* @date 2013-9-4
* @note begin modify by null
*/
@SuppressWarnings("serial")
@Scope("prototype")
@Controller
public class OnlineGraphAction extends BaseAction {
// 相对门户项目的相对路径
private String relativeStorageFilePath;
// 图形文件的文件名称
private String imgPath;
// 下载文件用户的
private InputStream inputStream;
/**
* \brief 下载产生的图片
*
* @return
* @attention
* @author 涂作权
* @date 2014-3-26
* @note begin modify by null
*/
public String download() throws Exception {
inputStream = new FileInputStream(
ProductsStorageUtils.graphAbsolutePath
+ relativeStorageFilePath + "/" + imgPath);
//这里的imgPath表示的是的是文件的名称,即:fName
String name = URLEncoder.encode(imgPath,"utf-8");
ActionContext.getContext().put("name", name);
return "download";
}
/**
* @return the imgPath
*/
public String getImgPath() {
return imgPath;
}
/**
* @param imgPath
* the imgPath to set
*/
public void setImgPath(String imgPath) {
this.imgPath = imgPath;
}
/**
* @return the inputStream
*/
public InputStream getInputStream() {
return inputStream;
}
/**
* @param inputStream
* the inputStream to set
*/
public void setInputStream(InputStream inputStream) {
this.inputStream = inputStream;
}
}
在struts配置文件中进行如下配置:
<action name="onlinegraph_*" class="cn.com.css.misps.onlinegraph.web.action.OnlineGraphAction" method="{1}">
<result name="download" type="stream">
<param name="inputName">inputStream</param>
<param name="contentDisposition">attachment;filename="${#name}"</param>
<param name="bufferSize">4096</param>
</result>
</action>
Struts2做下载相关推荐
- 用一个二维码做下载地址,自动区分是 ios 还是 android
用一个二维码做下载地址,自动区分是 ios 还是 android, 甚至区分 iphone 和 ipad. <html><head><meta http-equiv=& ...
- Struts2的下载安装
Struts2下载 使用Struts2框架,进行Web开发,或者运行Struts2的程序,必须,先下载并安装好Struts2 从Struts2的官网中进行下载 http://struts.apache ...
- spring boot结合FastDFSClient做下载文件注意事项
spring boot结合FastDFSClient做下载文件注意事项 1.后台下载方法走完后,前端页面浏览器一直没出现下载框. 2.ie浏览器兼容问题. 下面的FastDFSClient类依赖fdf ...
- 第一版简约资源网织梦cms源码 可做下载站或资源站
介绍: 模板可以做下载站也可以做资讯网站,模板整体很简洁. 发布文章的时候填写下载地址内容页的下载地址就会显示出来,不填不显示. 后台自定义设置软件评分. 默认百分之50. 关于我们.侵权处理.版权声 ...
- 简约资源网源码 可做下载站或资源站
介绍: 模板可以做下载站也可以做资讯网站,模板整体很简洁. 发布文章的时候填写下载地址内容页的下载地址就会显示出来,不填不显示. 后台自定义设置软件评分.默认百分之50. 关于我们.侵权处理.版权声明 ...
- 【转载】struts2实现下载文件的简单例子
以前做过的struts2下载,可是现在很久不用了竟然忘记了,现在在做的这个项目有用到,于是在网上搜索,发现这篇文章写得很不错,简单明了,转载过来,顺便给自己做个备忘吧. 转载自:http://blog ...
- PHP做下载文件的方法
1 <?php 2 header("Content-Type: application/force-download"); 3 header("Content-Di ...
- 使用struts2的 下载
jsp: <a href="testDownloadFiles!xiazai.action?fileName=aaa.rar">不带中文名的文件</a>&l ...
- 用一个二维码做下载app,自动区分是 ios 还是 android
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
最新文章
- 比特币的挑战者 BCH 带着开发者们来到湾区了!
- CUBLAS_STATUS_ALLOC_FAILED CUDA_ERROR_OUT_OF_MEMORY
- hive中,向map类型插入数据时,需要str_to_map一下
- FarPoint 应用总结
- java日志框架log4j详细配置及与slf4j联合使用教程
- python自动化测试——测试报告以附件形式发送邮件
- ThinkPHP分页链接支持数组参数的办法
- c#进阶(2)—— ASP.NET MVC 常用路由总结
- pg数据库开启远程连接_疫情之下,开启在家办公模式,远程连接工具篇之向日葵...
- simulink显示多个数据_如何在 Simulink 中使用 PID Tuner 进行 PID 调参?
- c++ array容器 传参_C++ 顺序容器基础知识总结
- 润乾单元格加html点击事件_报表输入页码翻页(润乾 V2018)
- Docker学习文档之三 其他相关-生产环境
- “华为”和“荣耀”手机有什么区别?
- 远程办公一晃一天,环境搭建履步维艰
- 第1天线性表顺序存储
- 概率论基础-严士健 第二版 习题与补充2.4答案
- 开发了一款开虚拟店通过百度网盘卖成千上万本电子书虚拟商品自动发货机器人软件助手
- 设计模式(一)设计模式的分类与区别
- 前端获取当前服务器时间,不使用客户端电脑时间
热门文章
- python中 lambda, map ,filter ,reduce讲解
- Java 中关于this、static、final 关键字的使用
- wxWidgets:wxSizerFlags类用法
- boost::local_shared_ptr相关的测试程序
- boost::mpl模块实现count相关的测试程序
- boost::mp11::mp_insert_c相关用法的测试程序
- boost::math::tools::cohen_acceleration用法的测试程序
- boost::hana::detail::create用法的测试程序
- boost::graph::distributed用法的测试程序
- boost::edge_connectivity用法的测试程序