shoppingbill
BlogJava
首頁
新隨筆
聯系
聚合
管理
隨筆分類
Core Java
(rss)
Design Pattern
(rss)
Hibernate
(rss)
RIA(1)
(rss)
SOA,SCA,OSGi(1)
(rss)
Spring(3)
(rss)
Struts 2(1)
(rss)
收藏夾
Servlet(2)
(rss)
隨筆檔案
2010年11月 (1)
2010年4月 (1)
2009年12月 (1)
2009年11月 (3)
最新隨筆
1.?ActionScript External API
2.?REST WebService與SOAP WebService的比較
3.?struts2文件下載
4.?Spring IoC
5.?Spring IDE
6.?Spring Validation Using Annotation
最新評論
struts2文件下載
Posted on 2009-12-17 00:01
shoppingbill
閱讀(515)
評論(0)
編輯
收藏
所屬分類:
Struts 2
/** */
/**
*
*/
package
com.download;
import
java.io.ByteArrayInputStream;
import
java.io.InputStream;
import
java.io.UnsupportedEncodingException;
import
org.apache.struts2.ServletActionContext;
import
com.opensymphony.xwork2.ActionSupport;
/** */
/**
*
@author
billzhang
*
*/
public
class
DownloadFileAction
extends
ActionSupport
{
@Override
public
String execute()
throws
Exception
{
return
"
success
"
;
}
public
InputStream getInputStream()
{
//
return new ByteArrayInputStream("struts2文件下載".getBytes());
return
ServletActionContext.
getServletContext().getResourceAsStream(
"
/upload/sw01-1.swf
"
);
}
public
String getFileName()
throws
UnsupportedEncodingException
{
String fileName
=
"
測試sw01-1.swf
"
;
return
new
String(fileName.getBytes(),
"
ISO8859-1
"
);
}
}
<?
xml version="1.0" encoding="UTF-8"
?>
<!
DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd"
>
<
struts
>
<
package
name
="struts2"
extends
="struts-default"
>
<
action
name
="downloadFile"
class
="com.download.DownloadFileAction"
>
<
result
name
="success"
type
="stream"
>
<
param
name
="contentType"
>
application/octet-stream;charset=ISO8859-1
</
param
>
<
param
name
="contentDisposition"
>
attachment;filename="${fileName}"
</
param
>
<
param
name
="inputName"
>
inputStream
</
param
>
<
param
name
="bufferSize"
>
4096
</
param
>
</
result
>
</
action
>
</
package
>
</
struts
>
今天在公司寫同樣的代碼就是不能用迅雷下載。回到家再寫一遍,我電腦上的迅雷就是可以的。hoho郁悶。今天搞了一天。沒有結果。本人初步判斷應該是公司電腦上的迅雷有問題。安裝的時候就有些文件復制失敗。hoho。。。。無語咯。
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
公告
本人最近會翻印國外spring教程。
常用鏈接
我的隨筆
我的評論
我的參與
評論排行榜
1.?ActionScript External API(0)
2.?REST WebService與SOAP WebService的比較(0)
3.?struts2文件下載(0)
4.?Spring IoC(0)
5.?Spring IDE(0)
閱讀排行榜
1.?Spring Validation Using Annotation(924)
2.?struts2文件下載(515)
3.?REST WebService與SOAP WebService的比較(466)
4.?Spring IDE(394)
5.?Spring IoC(250)
posts - 6, comments - 0, trackbacks - 0, articles - 0
Copyright © shoppingbill
主站蜘蛛池模板:
巧家县
|
仪征市
|
桐乡市
|
英山县
|
南开区
|
永修县
|
义乌市
|
黑河市
|
宁德市
|
灵武市
|
韩城市
|
太和县
|
政和县
|
罗定市
|
新化县
|
保定市
|
邢台县
|
灯塔市
|
大新县
|
洛宁县
|
松溪县
|
灵寿县
|
阿坝县
|
当雄县
|
长武县
|
焦作市
|
古交市
|
阿克苏市
|
仪陇县
|
蚌埠市
|
布尔津县
|
临西县
|
延津县
|
琼中
|
上饶县
|
敖汉旗
|
凌源市
|
临沂市
|
金昌市
|
凤冈县
|
洱源县
|