下载页面

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="download.action?FileName=Java.pdf">下载</a>
</body>
</html>

struts.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<!-- 开启开发者模式 -->
<constant name="struts.devMode" value="true"></constant>
<package name="jiangwenwen" namespace="/" extends="struts-default">
<action name="download" class="cn.jiangwenwen.action.DownLoadAction" method="download">
<result name="success" type="stream">
<param name="contentDisposition">
attachment;filename="${fileName}"
</param>
<param name="contentLength">
${fileSize}
</param>
<param name="contentType">
${contentType}
</param> </result>
</action>
</package>
</struts>

Action类

public class DownLoadAction extends ActionSupport{

	private String contentType;

	private String FileName;

	private InputStream inputStream;

	private long fileSize;

	public String download() throws FileNotFoundException {

		String rootpath = ServletActionContext.getServletContext().getRealPath("/");

		System.out.println(rootpath);

		System.out.println(FileName);

		File file = new File(rootpath+"/download/"+FileName);

		fileSize = file.length();

		inputStream = new FileInputStream(file);

		return SUCCESS;

	}

	public String getContentType() {
return contentType;
} public void setContentType(String contentType) {
this.contentType = contentType;
} public String getFileName() {
return FileName;
} public void setFileName(String fileName) {
FileName = fileName;
} public InputStream getInputStream() {
return inputStream;
} public void setInputStream(InputStream inputStream) {
this.inputStream = inputStream;
} public long getFileSize() {
return fileSize;
} public void setFileSize(long fileSize) {
this.fileSize = fileSize;
} }

Struts2之下载的更多相关文章

  1. Struts2之Struts2的下载与安装

    Struts2的下载 登陆struts的官网 下载Full Distribution这个选项的struts2的包. 这是Struts2的完整版,里面包括Struts2的实例应用,空实例应用,核心库,源 ...

  2. struts2类库下载

    struts2开发包下载 到http://struts.apache.org/download.cgi#struts2014下载struts-2.x.x-all.zip,目前最新版为2.1.6.下载完 ...

  3. Struts2 取消 下载时异常

    Struts2环境下,通过Struts2提供的下载方式进行下载时出现的java.lang.IllegalStateException异常 2011-1-820:34:20 org.apache.cat ...

  4. 4.struts2中的文件上传,下载

    Struts2中文件的上传下载,是借用commons里面的包实现文件的上传,需要导入两个jar commons-fileupload-1.2.2.jar commons-io-2.0.1.jar 实现 ...

  5. struts2 下载时报java.lang.IllegalStateException

    -----------------------------------------struts2 下载时报java.lang.IllegalStateException---------------- ...

  6. 【Java EE 学习 34】【struts2学习第一天】

    一.struts2简介 struts2是一个用来开发MVC应用程序的框架.它提供了Web应用程序开发过程中的一些常见问题的解决方案. 1.struts2的作用域范围:三层架构当中的第一层,相当于MVC ...

  7. Struts2配置文件

    Struts2配置文件 简介: 与Struts2相关的配置文件有好几个,常用的有 struts.properties , web.xml, struts.xml等.web.xml中配置Struts2的 ...

  8. struts2介绍

    struts2简介 Struts2框架发展 Struts于2000年5月由Craig McClanahan发起,并于 2001年7月发布了1.0版本,Struts一出现便大受欢迎,更成为了以后几年内w ...

  9. Struts2 初体验

    Sturts是一款优雅的,可扩展性很强的框架.它是由Struts开发团队和WebWord团队合作,共同开发的一个新的产品.新版本的Struts2 更加容易使用,更加接近Struts所追求的理念.从开发 ...

随机推荐

  1. BUUCTF--SimpleRev

    测试文件:https://buuoj.cn/files/7458c5c0ce999ac491df13cf7a7ed9f1/SimpleRev?token=eyJ0ZWFtX2lkIjpudWxsLCJ ...

  2. Jsp 自定义tag标签

    1转自:https://blog.csdn.net/yusimiao/article/details/46835617 Jsp自定义tag标签 自定义tag标签的好处 程序员可以自定一些特定功能的标记 ...

  3. C#.Net 调用Java的Web Service

    首先,得有一个web service地址:http://www.baiduc.om/XXServices?wsdl 然后在.net 项目中添加Web引用,并把地址给它输进去 第三.编码: using ...

  4. uwsgi配置cheaper模式进行自动弹性

    [uwsgi] socket = 0.0.0.0:8080 protocol = http master = true hara-kiri = 60 chdir = /home/test/projec ...

  5. [NOI2007]社交网络(最短路)

    [NOI2007]社交网络 Description 在社交网络(socialnetwork)的研究中,我们常常使用图论概念去解释一些社会现象.不妨看这样的一个问题. 在一个社交圈子里有n个人,人与人之 ...

  6. SSM三大框架整合梳理

    整合步骤 0.搭建动态web项目 1.需要的jar包 spring(包括springmvc) mybatis相关jar包 mybatis与spring的整合包(个人建议尽量使用高版本的,避免出现一些奇 ...

  7. MySQL数据库的自动备份与数据库被破坏后的恢复(2)

    测试自动备份正常运转与否(备份恢复的方法) 这里,以通过实际操作的过程来介绍问题出现后的恢复方法. [1] 当数据库被删除后的恢复方法 首先建立一个测试用的数据库. [root@CentOS ~]# ...

  8. 企业级监控软件Zabbix搭建部署之zabbix在WEB页面中的配置

    企业级监控软件zabbix搭建部署之zabbix在WEB页面中的配置 企业级监控软件zabbix搭建部署之zabbix在WEB页面中的配置 关于安装请看 http://www.linuxidc.com ...

  9. JavaWeb(四):JDBC

    数据持久化(persistence) 把数据保存到可掉电式存储设备中以供之后使用. 大多数情况下,特别是企业级应用,数据持久化意味着将内存中的数据保存到硬盘上加以”固化”,而持久化的实现过程大多通过各 ...

  10. Python3及Pycharm安装

    1.首先去python官网下载相应版本的Python安装包.如下: 2.下载完成后解压,双击exe文件进行安装,看到如下界面:Install Now表示默认安装:Customize installat ...