java - struts 2中的文件下载问题

标签 java jakarta-ee struts2 download

我的应用程序需要图像文件下载功能。我使用 Struts 2 流类型下载图像。文件下载成功但此时执行 Action 类是两次。如何解决这个问题?

<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 } 

最佳答案

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

不是有效的 contentDisposition。

尝试

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

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

关于java - struts 2中的文件下载问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19538793/

相关文章:

java - 我怎样才能为整个类抛出异常而不是一个方法一个方法地做

java - 如何使这项工作? - 安卓编程

java - 开发数据库简化管理器,我应该使用 JSF 还是 JSF+Hibernate?

java - Hibernate:从 Java 代码开始数据库布局

javascript - '错误 : `VideoPlayer` has no propType for native prop `VideoPlayerView.scaleY` of native type `number`

java - 关于java中的认证

java - 在 maven 中准备 Ear 文件

java - Struts2 填充列表

java - Stuts2 Tiles Tomcat疑似将UTF-8改成?

html - Struts2 文本区域调整大小