`
79343654
  • 浏览: 44631 次
  • 性别: Icon_minigender_1
  • 来自: 太原
社区版块
存档分类
最新评论

struts2文件下载示例

阅读更多

 

package com.topdt.policesms.action;

 

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.InputStream;

 

import org.apache.struts2.convention.annotation.Action;

import org.apache.struts2.convention.annotation.InterceptorRef;

import org.apache.struts2.convention.annotation.Namespace;

import org.apache.struts2.convention.annotation.ParentPackage;

import org.apache.struts2.convention.annotation.Result;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.annotation.Scope;

import org.springframework.stereotype.Controller;

 

import com.topdt.frame.base.Struts2Action;

import com.topdt.frame.common.AppContext;

import com.topdt.policesms.model.DataLog;

import com.topdt.policesms.service.DataLogService;

 

/**

 * 数据日志

 * @author Administrator

 *

 */

@Controller

@Scope("prototype")

@ParentPackage(value = "gloab-package")

@Namespace(value = "/message")

@Action(value = "dlog", results = {

@Result(name = "list", location = "/message/dlog/dlog_list.jsp"),

@Result(name = "download", type = "stream(类型为流)", params = { "contentType",

"application(应用程序)/octet-stream;charset=ISO8859-1", "inputName(输入文件名称)",

"fstream", "contentDisposition", "attachment;filename=${downloadFileName}",

"bufferSize", "4096" }),

@Result(name = "invalid.token",type="redirect",location = "task!list.action",params = {"message", "请不要重复提交" }) 

}, 

interceptorRefs = {

@InterceptorRef(value = "pageInterceptor", params = { "includeMethods", "list" }),

@InterceptorRef(value = "token", params = { "includeMethods", "save" }),

@InterceptorRef("topDtStack") 

})

public class DataLogAction extends Struts2Action<DataLog>{

 

private static final long serialVersionUID = 1792436660779570837L;

 

@Autowired

private DataLogService dataLogService;

private String statDate;

private String endDate;

private InputStream fstream;

private String inputPath;

private String fileName;

    public void setInputPath(String value) {

        inputPath = value;

    }

 

    public void setFileName(String fileName) {

this.fileName = fileName;

}

 

@Override

protected void doList() throws Exception {

list = dataLogService.queryDataLog(statDate, endDate, getModel().getDataType());

}

 

//取得文件名称

 

public String getDownloadFileName(){

    String downFileName=fileName;

    try {

downFileName=new String(downFileName.getBytes(),"ISO8859-1");

} catch (Exception e) {

e.printStackTrace();

}

return downFileName;

    }

//下载文件

public String downLog () {

inputPath = AppContext.getProperties("breakDataDir")+fileName;

try {

fstream = new FileInputStream(new File(inputPath));

} catch (FileNotFoundException e) {

e.printStackTrace();

}

return "download";

}

public DataLogService getDataLogService() {

return dataLogService;

}

 

public void setDataLogService(DataLogService dataLogService) {

this.dataLogService = dataLogService;

}

 

public String getStatDate() {

return statDate;

}

 

public void setStatDate(String statDate) {

this.statDate = statDate;

}

 

public String getEndDate() {

return endDate;

}

 

public void setEndDate(String endDate) {

this.endDate = endDate;

}

 

public InputStream getFstream() {

return fstream;

}

 

public void setFstream(InputStream fstream) {

this.fstream = fstream;

}

 

}

 

 

HTML :代码:<a href='dlog!downLog.action?fileName=<s:property value="#dlog.errorDetail"/>'>错误详细</a>

分享到:
评论

相关推荐

    struts2配置文件以及代码示例

    struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置...

    完整struts2文件上传示例

    最近在做struts2的学习研究,这里共享一份完整能运行的示例

    struts2中的文件上传和下载示例

    struts2中的文件上传和下载示例 struts2中的文件上传和下载示例 struts2中的文件上传和下载示例

    jsp中struts2.0标签应用示例

    jsp中struts2.0标签应用示例,介绍了部分标签的使用,里面有详细的文档说明。

    Struts2文件上传示例

    自己使用struts2写的一个文件上传示例代码,可以实现对文件的大小控制、格式控制等,里面注释写得比较详细,给大家分享一下子

    struts2文件上传下载示例

    基于struts2实现了单一文件上传,多文件上传和文件下载的功能.

    struts文件上传示例

    struts 上传文件的示例,是一个myeclipse工程

    Struts2文件上传程序示例

    本程序为struts2文件是上传程序。解压后就可以使用。程序比较简单适合于初学者。奔驰呢工序仅供参考。严禁用于其他用途

    struts2 in acton 示例源代码(2)

    struts2 in acton 示例源代码,文件超过15M,只能分开了。

    struts2 文件上传和下载示例程序

    struts2 文件上传和下载示例程序 http://blog.csdn.net/zhiweiv/archive/2008/10/13/3070610.aspx

    Struts2 上传图片示例

    Struts2 的简单上传。功能基本实现。

    Struts2学习示例

    struts2 示例 目的:构建struts2开发框架 适合:有一定struts2基础 实现:通过对用户信息的基本操作来给大家做个示范 1、struts2的搭建 2、web.xml文件的简单配置 3、struts.xml文件的简单配置 4、网站初始化工作...

    struts.xml文件详解示例代码

    struts.xml文件详解示例代码,可以参照http://blog.csdn.net/jiajia333666/article/details/47979919 阅读。

    struts1上传下载示例

    文档讲述了利用strurts1来上传和下载文件,远程也可以进行上传和下载!

    struts-2.5.16-源码+示例(S2-057漏洞演示环境)

    文件包含struts-2.5.16-源码+示例,利用附件文件可以很方便的搭建出调试S2-057的漏洞环境,欢迎各位取用

    struts2+ireport+jasperreport报表设计简单示例

    使用ireport和struts2进行报表设计的简单示例,生成普通报表和饼图、柱状图。java工程的lib里包含丰富的jar包,且很多都是从各个网站下载的最新版本,文件夹内还包含一些ireport和jasperreport文档,适合刚入门学习...

    struts2文件下载

    通过struts2实现以action的方式来下载文件的示例代码

    struts2+hibernate学习示例

    struts2+Hibernate 示例 目的:构建struts2开发框架 使用 Hibernate作为持久层操作 适合:有一定struts2基础 实现:通过对用户信息的基本操作来给大家做个示范 1、struts2的搭建 2、web.xml文件的简单配置 3、...

    Apache Struts 2 文档(struts-2.5.28.3-docs.zip)

    Apache Struts 2 文档(struts-2.5.28.3-docs.zip),Apache Struts 2.5.28.3是一个优雅的、可扩展的框架,用于创建企业级 Java Web 应用程序。它可以在完整发行版中使用,也可以作为单独的库、源代码、示例和文档...

Global site tag (gtag.js) - Google Analytics