【问题标题】:file download issue in struts 2struts 2中的文件下载问题
【发布时间】:2013-10-23 10:10:57
【问题描述】:

我的应用程序需要图像文件下载功能。我使用 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=[com.tt.test.action.DownloadAction@4e836869, com.opensymphony.xwork2.DefaultTextProvider@cb78915], 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 [com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter@256d6cf]
2013-10-23 15:19:55.934 [DEBUG] com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler:57 - Entering nullPropertyValue [target=[com.tt.test.action.DownloadAction@4e836869, com.opensymphony.xwork2.DefaultTextProvider@cb78915], 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 [com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter@256d6cf]
2013-10-23 15:19:55.940 [DEBUG] com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler:57 - Entering nullPropertyValue [target=[com.tt.test.action.DownloadAction@4e836869, com.opensymphony.xwork2.DefaultTextProvider@cb78915], 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 [com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter@256d6cf]
2013-10-23 15:19:55.947 [DEBUG] com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler:57 - Entering nullPropertyValue [target=[com.tt.test.action.DownloadAction@4e836869, com.opensymphony.xwork2.DefaultTextProvider@cb78915], 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 [com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter@256d6cf]
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=[com.opensymphony.xwork2.DefaultTextProvider@cb78915], property=struts]
2013-10-23 15:19:56.405 [DEBUG] com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler:57 - Entering nullPropertyValue [target=[com.opensymphony.xwork2.DefaultTextProvider@cb78915], 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=[com.tt.test.action.DownloadAction@3012db7c, com.opensymphony.xwork2.DefaultTextProvider@cb78915], 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 [com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter@256d6cf]
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 [com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter@256d6cf]
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 com.tt.test.action.DownloadAction@3012db7c
2013-10-23 15:19:56.475 [DEBUG] com.opensymphony.xwork2.interceptor.PrefixMethodInvocationUtil:57 - cannot find method [validateMddownload] in action [com.tt.test.action.DownloadAction@3012db7c]
2013-10-23 15:19:56.476 [DEBUG] com.opensymphony.xwork2.interceptor.PrefixMethodInvocationUtil:57 - cannot find method [validateDoMddownload] in action [com.tt.test.action.DownloadAction@3012db7c]
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=[com.tt.test.action.DownloadAction@3012db7c, com.opensymphony.xwork2.DefaultTextProvider@cb78915], 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 [com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter@256d6cf]
2013-10-23 15:19:56.558 [DEBUG] com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler:57 - Entering nullPropertyValue [target=[com.tt.test.action.DownloadAction@3012db7c, com.opensymphony.xwork2.DefaultTextProvider@cb78915], 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 [com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter@256d6cf]
2013-10-23 15:19:56.563 [DEBUG] com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler:57 - Entering nullPropertyValue [target=[com.tt.test.action.DownloadAction@3012db7c, com.opensymphony.xwork2.DefaultTextProvider@cb78915], 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 [com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter@256d6cf]
2013-10-23 15:19:56.567 [DEBUG] com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler:57 - Entering nullPropertyValue [target=[com.tt.test.action.DownloadAction@3012db7c, com.opensymphony.xwork2.DefaultTextProvider@cb78915], 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 [com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter@256d6cf]
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 } 

【问题讨论】:

  • 在系统浏览器中action类只执行一次,而手机浏览器action类执行两次

标签: java jakarta-ee struts2 download


【解决方案1】:
<param name="contentDisposition">contentDisposition</param>

不是有效的 contentDisposition。

试试

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

其中 fileName 是下载操作中的字符串(通过 getter 公开)。

【讨论】:

  • contentDisposition 是我的动作类中的一个变量。在我设置附件的 setter 方法中;filename="tst.jpg"
  • 那么应该是&lt;param name="contentDisposition"&gt;${contentDisposition}&lt;/param&gt;
  • 谢谢..它正在工作..在系统浏览器中,动作类只执行一次。但移动浏览器动作类执行两次
  • use FireBug or something similar on your mobile browser 看看有多少请求正在启动。然后通过添加此信息来编辑您的问题。
  • 我在移动设备中使用了另一个浏览器,动作类只执行了一次..谢谢你..但是默认移动浏览器执行动作类两次
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-03
  • 1970-01-01
  • 2011-07-20
  • 1970-01-01
  • 2011-01-08
  • 2014-08-24
相关资源
最近更新 更多