This is an automated email from the ASF dual-hosted git repository.
git-site-role pushed a commit to branch asf-site
in repository https://gitbox.apache.org/repos/asf/struts-site.git
The following commit(s) were added to refs/heads/asf-site by this push:
new a8af3573b Automatic Site Publish by Buildbot
a8af3573b is described below
commit a8af3573b7e5e95eb9f0c40cdf6ab45d6b36594d
Author: buildbot
AuthorDate: Fri Jan 12 12:24:37 2024 +
Automatic Site Publish by Buildbot
---
...or.html => action-file-upload-interceptor.html} | 77
.../core-developers/file-upload-interceptor.html | 6 +-
output/core-developers/file-upload.html| 48 -
output/core-developers/interceptors.html | 194 +++--
output/download.html | 2 +-
5 files changed, 182 insertions(+), 145 deletions(-)
diff --git a/output/core-developers/file-upload-interceptor.html
b/output/core-developers/action-file-upload-interceptor.html
similarity index 77%
copy from output/core-developers/file-upload-interceptor.html
copy to output/core-developers/action-file-upload-interceptor.html
index 800fd990d..310dffc9d 100644
--- a/output/core-developers/file-upload-interceptor.html
+++ b/output/core-developers/action-file-upload-interceptor.html
@@ -7,7 +7,7 @@
- File Upload Interceptor
+ Action File Upload Interceptor
@@ -146,25 +146,21 @@
-https://github.com/apache/struts-site/edit/master/source/core-developers/file-upload-interceptor.md";
title="Edit this page on GitHub">Edit on GitHub
+https://github.com/apache/struts-site/edit/master/source/core-developers/action-file-upload-interceptor.md";
title="Edit this page on GitHub">Edit on GitHub
-<< back to
Interceptors
+<< back to
Interceptors
-File Upload Interceptor
+Action File Upload Interceptor
+
+
+ Available since Struts 6.4.0 as replacement for File Upload Interceptor
+
See this page for more examples and advanced
configuration.
Interceptor that is based off of MultiPartRequestWrapper, which is automatically
applied for any request that includes
-a file. It adds the following parameters, where is the
name given to the file uploaded by the HTML form:
-
-
- : File
- the actual File
- ContentType: String - the content type of the file
- FileName: String - the actual name of the file uploaded (not
the HTML name)
-
-
-You can get access to these files by merely providing setters in your
action that correspond to any of the three patterns
-above, such as setDocument(File document), setDocumentContentType(String
contentType), etc.
+a file. If an action implements org.apache.struts2.action.UploadedFilesAware
interface, the interceptor will pass
+information and content of uploaded files using the callback method withUploadedFiles(List).
See the example code section.
@@ -203,7 +199,7 @@ and which are not.
Example action mapping:
-
+
good_result.jsp
@@ -225,34 +221,27 @@ and which are not.
Example Action class:
-package com.example;
-
-import java.io.File;
-import com.opensymphony.xwork2.ActionSupport;
-
-public UploadAction extends ActionSupport {
- private File file;
- private String contentType;
- private String filename;
-
- public void setUpload(File
file) {
- this.file = file;
- }
-
- public void setUploadContentType(String contentType) {
- this.contentType = contentType;
- }
-
- public void setUploadFileName(String filename) {
- this.filename = filename;
- }
-
- public String execute() {
- //...
- return SUCCESS;
- }
- }
-
+public class UploadAction extends ActionSupport implements UploadedFilesAware {
+ private UploadedFile uploadedFile;
+ private String contentType;
+ private String fileName;
+ private String originalName;
+
+ @Override
+ public void withUploadedFiles(List uploadedFiles) {
+ if (!uploadedFiles.isEmpty()) {
+ this.uploadedFile = uploadedFiles.get(0);
+ this.fileName = uploadedFile.getName();
+ this.contentType = uploadedFile.getContentType();
+ this.originalName = uploadedFile.getOriginalName();
+ }
+ }
+
+ public String execute() {
+ //do something with the file
+ return SUCCESS;
+ }
+}
Setting parameters example:
@@ -264,7 +253,7 @@ and which are not.
-This part is optional and would be done in place of the line in the action mapping
+This part is optional and would be done in place of the