JSP开发之Struts2实现下载功能的实例
程序员文章站
2023-10-27 22:54:52
jsp开发之struts2实现下载功能的实例
1、action 类
package com.favccxx.strutsdemo;
import...
jsp开发之struts2实现下载功能的实例
1、action 类
package com.favccxx.strutsdemo; import java.io.file; import java.io.fileinputstream; import java.io.inputstream; import com.opensymphony.xwork2.actionsupport; public class downloadaction extends actionsupport { private static final long serialversionuid = -7758584364932001138l; private inputstream inputstream; @override public string execute() throws exception { inputstream = new fileinputstream(new file("d:\\芒果豆.jpg")); return success; } public inputstream getinputstream() { return inputstream; } public void setinputstream(inputstream inputstream) { this.inputstream = inputstream; } }
2、struts.xml
<?xml version="1.0" encoding="utf-8" ?> <!doctype struts public "-//apache software foundation//dtd struts configuration 2.3//en" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <constant name="struts.enable.dynamicmethodinvocation" value="false" /> <constant name="struts.devmode" value="true" /> <package name="default" namespace="/" extends="struts-default"> <default-action-ref name="index" /> <global-results> <result name="error">/error.jsp</result> </global-results> <global-exception-mappings> <exception-mapping exception="java.lang.exception" result="error"/> </global-exception-mappings> <action name="index"> <result type="redirectaction"> <param name="actionname">helloworld</param> <param name="namespace">/example</param> </result> </action> <action name="download" class="com.favccxx.strutsdemo.downloadaction"> <result name="success" type="stream"> <param name="contenttype">application/octet-stream</param> <param name="inputname">inputstream</param> <param name="contentdisposition">attachment;filename="mongo.jpg"</param> <param name="buffersize">1024</param> </result> </action> </package> </struts>
3、web.xml
<?xml version="1.0" encoding="utf-8"?> <web-app id="webapp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>struts blank</display-name> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app>
4、jsp
<a href="/download" rel="external nofollow" >无注解下载</a>
以上就是jsp实现下载功能的实例代码,如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
推荐阅读
-
JSP开发之Struts2实现下载功能的实例
-
Android开发之ListView功能扩展,实现高性能的瀑布流布局讲解
-
Android开发实现可拖动排序的ListView功能【附源码下载】
-
C#实现的Windows剪贴板监视器功能实例【附demo源码下载】
-
Android开发实现的简单计算器功能【附完整demo源码下载】
-
iOS开发中文件的上传和下载功能的基本实现
-
[tip]用jsp实现直接下载文件而不是在浏览器中打开的功能
-
JSP开发之hibernate之单向多对一关联的实例
-
运用JSP+ajax实现分类查询功能的实例代码
-
Winform开发框架之参数配置管理功能实现-基于SettingsProvider.net的构建