2013-10-23 99 views
0

我在我的應用程序中需要圖像文件下載功能。我使用Struts 2流類型下載圖像。文件下載成功,但當時執行動作類是兩次。如何解決這個問題呢?struts 2中的文件下載問題

<action name="download" class="com.ft.bsnl.hb.action.DownloadAction" method="mddownload"> 

     <result name="success" type="stream" > 

       <param name="contentType">image/jpeg</param> 
       <param name="inputName">fileToDownload</param> 
       <param name="contentDisposition">contentDisposition</param> 

     </result> 
     <result name="failed">/jsp/DownloadComplete.jsp</result> 
</action> 

我的日誌

Inner of Download Process..... 

Return Status : success 
2013-10-23 15:19:55.927 [DEBUG] com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler:57 - Entering nullPropertyValue [target=[[email protected], [email protected]], property=inputName] 
2013-10-23 15:19:55.929 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - Property: contentType 
2013-10-23 15:19:55.929 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - Class: com.tt.test.action.DownloadAction 
2013-10-23 15:19:55.931 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - field-level type converter for property [contentType] = none found 
2013-10-23 15:19:55.932 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - global-level type converter for property [contentType] = none found 
2013-10-23 15:19:55.933 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - falling back to default type converter [[email protected]6cf] 
2013-10-23 15:19:55.934 [DEBUG] com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler:57 - Entering nullPropertyValue [target=[[email protected], [email protected]], property=contentLength] 
2013-10-23 15:19:55.935 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - Property: contentType 
2013-10-23 15:19:55.936 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - Class: com.tt.test.action.DownloadAction 
2013-10-23 15:19:55.937 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - field-level type converter for property [contentType] = none found 
2013-10-23 15:19:55.938 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - global-level type converter for property [contentType] = none found 
2013-10-23 15:19:55.939 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - falling back to default type converter [[email protected]6cf] 
2013-10-23 15:19:55.940 [DEBUG] com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler:57 - Entering nullPropertyValue [target=[[email protected], [email protected]], property=bufferSize] 
2013-10-23 15:19:55.941 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - Property: contentType 
2013-10-23 15:19:55.942 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - Class: com.tt.test.action.DownloadAction 
2013-10-23 15:19:55.943 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - field-level type converter for property [contentType] = none found 
2013-10-23 15:19:55.944 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - global-level type converter for property [contentType] = none found 
2013-10-23 15:19:55.945 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - falling back to default type converter [[email protected]6cf] 
2013-10-23 15:19:55.947 [DEBUG] com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler:57 - Entering nullPropertyValue [target=[[email protected], [email protected]], property=contentCharSet] 
2013-10-23 15:19:55.947 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - Property: contentType 
2013-10-23 15:19:55.948 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - Class: com.tt.test.action.DownloadAction 
2013-10-23 15:19:55.948 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - field-level type converter for property [contentType] = none found 
2013-10-23 15:19:55.949 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - global-level type converter for property [contentType] = none found 
2013-10-23 15:19:55.949 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - falling back to default type converter [[email protected]6cf] 
2013-10-23 15:19:55.951 [DEBUG] org.apache.struts2.dispatcher.StreamResult:57 - Streaming result [fileToDownload] type=[image/jpg] length=[null] content-disposition=[attachment;filename=FW000001.jpg] charset=[null] 
2013-10-23 15:19:55.951 [DEBUG] org.apache.struts2.dispatcher.StreamResult:57 - Streaming to output buffer +++ START +++ 
2013-10-23 15:19:55.952 [DEBUG] org.apache.struts2.dispatcher.StreamResult:57 - Streaming to output buffer +++ END +++ 
2013-10-23 15:19:55.953 [DEBUG] com.opensymphony.xwork2.interceptor.I18nInterceptor:57 - after Locale=en_GB 
2013-10-23 15:19:55.953 [DEBUG] com.opensymphony.xwork2.interceptor.I18nInterceptor:57 - intercept } 
2013-10-23 15:19:56.404 [DEBUG] com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler:57 - Entering nullPropertyValue [target=[[email protected]], property=struts] 
2013-10-23 15:19:56.405 [DEBUG] com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler:57 - Entering nullPropertyValue [target=[[email protected]], property=struts] 
2013-10-23 15:19:56.406 [DEBUG] com.opensymphony.xwork2.config.ConfigurationManager:57 - Checking ConfigurationProviders for reload. 
2013-10-23 15:19:56.407 [DEBUG] com.opensymphony.xwork2.DefaultActionProxy:57 - Creating an DefaultActionProxy for namespace/and action name download 
2013-10-23 15:19:56.408 [DEBUG] org.springframework.beans.factory.support.DefaultListableBeanFactory:245 - Returning cached instance of singleton bean 'servletContext' 
2013-10-23 15:19:56.409 [DEBUG] org.springframework.beans.factory.support.DefaultListableBeanFactory:1140 - Added autowiring by name from bean name 'com.tt.test.action.DownloadAction' via property 'servletContext' to bean named 'servletContext' 
2013-10-23 15:19:56.410 [DEBUG] com.opensymphony.xwork2.interceptor.I18nInterceptor:57 - intercept '//download' { 
2013-10-23 15:19:56.410 [DEBUG] com.opensymphony.xwork2.interceptor.I18nInterceptor:57 - applied invocation context locale=en_US 
2013-10-23 15:19:56.411 [DEBUG] com.opensymphony.xwork2.interceptor.I18nInterceptor:57 - before Locale=en_US 
2013-10-23 15:19:56.412 [DEBUG] com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler:57 - Entering nullPropertyValue [target=[[email protected], [email protected]], property=struts] 
2013-10-23 15:19:56.412 [DEBUG] org.apache.struts2.interceptor.FileUploadInterceptor:57 - Bypassing //download 
2013-10-23 15:19:56.413 [DEBUG] com.opensymphony.xwork2.interceptor.StaticParametersInterceptor:57 - Setting static parameters {} 
2013-10-23 15:19:56.414 [DEBUG] com.opensymphony.xwork2.interceptor.ParametersInterceptor:57 - Setting params NONE 
2013-10-23 15:19:56.414 [DEBUG] com.opensymphony.xwork2.interceptor.ParametersInterceptor:57 - Setting params Req => [ ps1 ] id => [ Ps1WP1 ] 
2013-10-23 15:19:56.415 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - Property: Req 
2013-10-23 15:19:56.416 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - Class: com.tt.test.action.DownloadAction 
2013-10-23 15:19:56.417 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - field-level type converter for property [Req] = none found 
2013-10-23 15:19:56.417 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - global-level type converter for property [Req] = none found 
2013-10-23 15:19:56.418 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - falling back to default type converter [[email protected]6cf] 
2013-10-23 15:19:56.419 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - Property: id 
2013-10-23 15:19:56.419 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - Class: com.tt.test.action.DownloadAction 
2013-10-23 15:19:56.420 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - field-level type converter for property [id] = none found 
2013-10-23 15:19:56.421 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - global-level type converter for property [id] = none found 
2013-10-23 15:19:56.422 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - falling back to default type converter [[email protected]6cf] 
2013-10-23 15:19:56.423 [DEBUG] org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor:57 - Validating //download with method mddownload. 
2013-10-23 15:19:56.474 [DEBUG] com.opensymphony.xwork2.validator.ValidationInterceptor:57 - Invoking validate() on action [email protected] 
2013-10-23 15:19:56.475 [DEBUG] com.opensymphony.xwork2.interceptor.PrefixMethodInvocationUtil:57 - cannot find method [validateMddownload] in action [[email protected]] 
2013-10-23 15:19:56.476 [DEBUG] com.opensymphony.xwork2.interceptor.PrefixMethodInvocationUtil:57 - cannot find method [validateDoMddownload] in action [[email protected]] 
2013-10-23 15:19:56.476 [DEBUG] com.opensymphony.xwork2.DefaultActionInvocation:57 - Executing action method = mddownload 



Inner of Download Process..... 



Return Status : success 

2013-10-23 15:19:56.553 [DEBUG] com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler:57 - Entering nullPropertyValue [target=[[email protected], [email protected]], property=inputName] 
2013-10-23 15:19:56.554 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - Property: contentType 
2013-10-23 15:19:56.554 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - Class: com.tt.test.action.DownloadAction 
2013-10-23 15:19:56.555 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - field-level type converter for property [contentType] = none found 
2013-10-23 15:19:56.555 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - global-level type converter for property [contentType] = none found 
2013-10-23 15:19:56.555 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - falling back to default type converter [[email protected]6cf] 
2013-10-23 15:19:56.558 [DEBUG] com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler:57 - Entering nullPropertyValue [target=[[email protected], [email protected]], property=contentLength] 
2013-10-23 15:19:56.560 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - Property: contentType 
2013-10-23 15:19:56.561 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - Class: com.tt.test.action.DownloadAction 
2013-10-23 15:19:56.561 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - field-level type converter for property [contentType] = none found 
2013-10-23 15:19:56.562 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - global-level type converter for property [contentType] = none found 
2013-10-23 15:19:56.562 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - falling back to default type converter [[email protected]6cf] 
2013-10-23 15:19:56.563 [DEBUG] com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler:57 - Entering nullPropertyValue [target=[[email protected], [email protected]], property=bufferSize] 
2013-10-23 15:19:56.563 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - Property: contentType 
2013-10-23 15:19:56.564 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - Class: com.tt.test.action.DownloadAction 
2013-10-23 15:19:56.564 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - field-level type converter for property [contentType] = none found 
2013-10-23 15:19:56.565 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - global-level type converter for property [contentType] = none found 
2013-10-23 15:19:56.566 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - falling back to default type converter [[email protected]256d6cf] 
2013-10-23 15:19:56.567 [DEBUG] com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler:57 - Entering nullPropertyValue [target=[[email protected], [email protected]], property=contentCharSet] 
2013-10-23 15:19:56.567 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - Property: contentType 
2013-10-23 15:19:56.568 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - Class: com.tt.test.action.DownloadAction 
2013-10-23 15:19:56.569 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - field-level type converter for property [contentType] = none found 
2013-10-23 15:19:56.570 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - global-level type converter for property [contentType] = none found 
2013-10-23 15:19:56.570 [DEBUG] com.opensymphony.xwork2.conversion.impl.XWorkConverter:57 - falling back to default type converter [[email protected]6cf] 
2013-10-23 15:19:56.571 [DEBUG] org.apache.struts2.dispatcher.StreamResult:57 - Streaming result [fileToDownload] type=[image/jpg] length=[null] content-disposition=[attachment;filename=FW000001.jpg] charset=[null] 
2013-10-23 15:19:56.572 [DEBUG] org.apache.struts2.dispatcher.StreamResult:57 - Streaming to output buffer +++ START +++ 
2013-10-23 15:19:56.573 [DEBUG] org.apache.struts2.dispatcher.StreamResult:57 - Streaming to output buffer +++ END +++ 
2013-10-23 15:19:56.574 [DEBUG] com.opensymphony.xwork2.interceptor.I18nInterceptor:57 - after Locale=en_US 
2013-10-23 15:19:56.574 [DEBUG] com.opensymphony.xwork2.interceptor.I18nInterceptor:57 - intercept } 
+0

在系統瀏覽器中,動作類只有一次execute.but移動瀏覽器動作類兩次執行 – Palaniraja

回答

1
<param name="contentDisposition">contentDisposition</param> 

不是有效contentDisposition。

嘗試

<param name="contentDisposition">attachment;filename="${fileName}"</param> 

其中FileName是在下載操作的字符串(通過一個getter暴露)。

+0

contentDisposition是我的動作類中的一個變量。在setter方法中我設置了附件; filename =「tst.jpg」 – Palaniraja

+0

then它應該是' $ {contentDisposition}' –

+0

謝謝..它的工作..在系統瀏覽器中的動作類只有一次execute.but手機瀏覽器動作類兩次執行 – Palaniraja