使用struts2如何实现文件下载功能-创新互联
本篇文章为大家展示了使用struts2如何实现文件下载功能,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
创新互联建站主要从事做网站、成都网站制作、网页设计、企业做网站、公司建网站等业务。立足成都服务永城,十年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:189820811081. 项目结构

2. web.xml
struts 2 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter struts 2 /* index.jsp 30
3.DownloadAction.java
package com.action;
import java.io.InputStream;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class DownloadAction extends ActionSupport{
private static final long serialVersionUID = 1L;
//文件路径
private String path;
//path属性的getter方法
public String getPath(){
return path;
}
//path属性的setter方法
public void setPath(String path){
this.path = path;
}
//返回inputstream,文件下载关键方法
public java.io.InputStream getDownloadFile() throws Exception{
InputStream in = ServletActionContext.getServletContext().getResourceAsStream(getPath());
return in;
}
public String execute() throws Exception{
return SUCCESS;
}
}4.struts.xml
image/jpeg attachment;filename="a.jpg" downloadFile 1024
5.index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>" rel="external nofollow" > 首页 欢迎来到首页,点下面链接去下载一个文件
">下载
上述内容就是使用struts2如何实现文件下载功能,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注创新互联行业资讯频道。
本文名称:使用struts2如何实现文件下载功能-创新互联
标题路径:http://www.scyingshan.cn/article/cooedg.html


咨询
建站咨询
