下载页面

<%@ 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. win32 socket 编程(一)——TCP/IP

    一.基本概念 a) 同步:指发送方发出数据后,等收到接收方发回的响应,才发下一个数据包的通信方式. nb)异步:指的是发送方不等接收方响应,便接着发下个数据包的通信方式. c) 阻塞:指调用某函数时, ...

  2. 在vsCode中用git命令合并分支

    提交修改代码到本地仓库 $ git commit -m "修改的东西的描述"切换到master主分支上 $ git checkout master拉取主分支上面的代码 $ git ...

  3. 微信小程序倒计时实现功能

    onLoad: function () {    var that=this;    this.data.intervarID= setInterval(function () {      var ...

  4. linux ab压力测试

    1.安装 yum -y install httpd-tools 2.检测版本 ab -V 3.常用 ab -c -n 127.0.0.1/index.php #同时处理100个请求并运行10次inde ...

  5. 切面AOP的切点@Pointcut用法

    格式: execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern ...

  6. [web 安全] php随机数安全问题

    and() 和 mt_rand() 产生随机数srand() 和 mt_srand() 播种随机数种子(seed)使用: <?php srand(123);//播种随机数种子 for($i=0; ...

  7. Django的下载和基本指令

    1.下载Django pip3  install  django     #不写版本号的话,默认使下载最新版的django pip3  install   django == 2.1.2    #指定 ...

  8. Task2.设立计算图并自动计算

    1.numpy和pytorch实现梯度下降法 import numpy as np # N is batch size; N, D_in, H, D_out = 64, 1000, 100, 10 # ...

  9. tensorflow图像处理函数(1)

    1.tensorflow中对jpeg格式图像的编码/解码函数: import matplotlib.pyplot as plt import tensorflow as tf image_raw_da ...

  10. java.nio.channels.IllegalBlockingModeException

    报错信息如下: Exception in thread "main" java.nio.channels.IllegalBlockingModeException at java. ...