博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
struts2——文件下载(简单的功能)
阅读量:4656 次
发布时间:2019-06-09

本文共 1619 字,大约阅读时间需要 5 分钟。

1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2     pageEncoding="UTF-8"%> 3 <%@taglib uri="/struts-tags" prefix="s"%> 4  5  6      7         
8 struts2的一个例子 9 10 11
12
13
14 15 16
index.jsp代码
1 
2 5
6
7
8
9
10
fileInputStream11
attachment;filename=image.jpg12
application/octet-stream13
14
15
16
struts.xml代码
1 package com.xiaostudy.web; 2  3 import java.io.File; 4 import java.io.FileInputStream; 5 import java.io.FileNotFoundException; 6 import java.io.InputStream; 7  8 import org.apache.struts2.ServletActionContext; 9 10 import com.opensymphony.xwork2.ActionSupport;11 12 public class DownloadFile extends ActionSupport {13     14     public InputStream fileInputStream;15     public String downloadFile() throws FileNotFoundException {16         17         String path = ServletActionContext.getServletContext().getRealPath("/WEB-INF/files/CSS.jpg");18         fileInputStream = new FileInputStream(new File(path));19         20         return SUCCESS;21     }22     public InputStream getFileInputStream() {23         return fileInputStream;24     }25     public void setFileInputStream(InputStream fileInputStream) {26         this.fileInputStream = fileInputStream;27     }28 29 30 }
action动作类DownloadFile

 

转载于:https://www.cnblogs.com/xiaostudy/p/9452227.html

你可能感兴趣的文章
【蓝桥杯】逆波兰表达式
查看>>
浏览器-04 WebKit 渲染2
查看>>
异常处理
查看>>
页签切换
查看>>
基于MyBatis框架链接数据库
查看>>
扩展 Jianyi的SmartQuery,正式发布 ListQuery WebPart,已发布到Codeplex.CamlQuery项目中...
查看>>
jenkins配置邮箱服务器(126邮箱)
查看>>
Java中String类通过new创建与直接赋值的区别
查看>>
文件实时同步(rsync+inotify)
查看>>
AlertDialog
查看>>
《设计前的质量》阅读笔记1
查看>>
python闭包和延迟绑定
查看>>
C#设计模式系列 3 ----Strategy 策略模式 之--007大破密码危机
查看>>
访问树中的所有元素(DOM)
查看>>
(转)C#制作进度窗体
查看>>
博客园页面设置
查看>>
【Alpha】Daily Scrum Meeting第五次
查看>>
git 路径中文转换成编码的解决
查看>>
2.19
查看>>
win10安装mongodb-win32-x86_64-2008plus-ssl-3.4.10-signed
查看>>