diff --git a/file-upload/pom.xml b/file-upload/pom.xml index 679e023c..278a676a 100644 --- a/file-upload/pom.xml +++ b/file-upload/pom.xml @@ -29,9 +29,7 @@ /${project.artifactId} - CTRL+C - 8999 - 10 + 10 diff --git a/file-upload/src/main/java/org/apache/struts/example/Upload.java b/file-upload/src/main/java/org/apache/struts/example/UploadAction.java similarity index 65% rename from file-upload/src/main/java/org/apache/struts/example/Upload.java rename to file-upload/src/main/java/org/apache/struts/example/UploadAction.java index a647763e..7797c2e8 100644 --- a/file-upload/src/main/java/org/apache/struts/example/Upload.java +++ b/file-upload/src/main/java/org/apache/struts/example/UploadAction.java @@ -20,13 +20,18 @@ package org.apache.struts.example; import org.apache.struts2.ActionSupport; +import org.apache.struts2.action.UploadedFilesAware; +import org.apache.struts2.dispatcher.multipart.UploadedFile; import java.io.File; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Stream; /** * Allows upload a file */ -public class Upload extends ActionSupport { +public class UploadAction extends ActionSupport implements UploadedFilesAware { private File[] upload; private String[] uploadFileName; @@ -36,27 +41,26 @@ public String execute() throws Exception { return INPUT; } - public File[] getUpload() { - return upload; + public String upload() throws Exception { + return SUCCESS; } - public void setUpload(File[] upload) { - this.upload = upload; + public File[] getUpload() { + return upload; } public String[] getUploadFileName() { return uploadFileName; } - public void setUploadFileName(String[] uploadFileName) { - this.uploadFileName = uploadFileName; - } - public String[] getUploadContentType() { return uploadContentType; } - public void setUploadContentType(String[] uploadContentType) { - this.uploadContentType = uploadContentType; + @Override + public void withUploadedFiles(List uploadedFiles) { + upload = uploadedFiles.stream().map(UploadedFile::getContent).toArray(File[]::new); + uploadFileName = uploadedFiles.stream().map(UploadedFile::getName).toArray(String[]::new); + uploadContentType = uploadedFiles.stream().map(UploadedFile::getContentType).toArray(String[]::new); } } diff --git a/file-upload/src/main/resources/struts.xml b/file-upload/src/main/resources/struts.xml index 1008ab63..8e9bf370 100644 --- a/file-upload/src/main/resources/struts.xml +++ b/file-upload/src/main/resources/struts.xml @@ -1,7 +1,7 @@ + "-//Apache Software Foundation//DTD Struts Configuration 6.0//EN" + "https://struts.apache.org/dtds/struts-6.0.dtd"> @@ -12,11 +12,16 @@ - upload + input - + + WEB-INF/input.jsp + + + + WEB-INF/upload.jsp WEB-INF/upload.jsp diff --git a/file-upload/src/main/webapp/WEB-INF/input.jsp b/file-upload/src/main/webapp/WEB-INF/input.jsp new file mode 100644 index 00000000..02b247b2 --- /dev/null +++ b/file-upload/src/main/webapp/WEB-INF/input.jsp @@ -0,0 +1,20 @@ +<%@ page contentType="text/html; charset=UTF-8" %> +<%@ taglib prefix="s" uri="/struts-tags" %> + + + File upload: input + + + + + + + + + + + + + + + diff --git a/file-upload/src/main/webapp/WEB-INF/upload.jsp b/file-upload/src/main/webapp/WEB-INF/upload.jsp index 247293a9..62cb89c7 100644 --- a/file-upload/src/main/webapp/WEB-INF/upload.jsp +++ b/file-upload/src/main/webapp/WEB-INF/upload.jsp @@ -2,17 +2,16 @@ <%@ taglib prefix="s" uri="/struts-tags" %> - File upload + File upload: result - - - - - - +

+back to input +

+ +
diff --git a/file-upload/src/main/webapp/WEB-INF/web.xml b/file-upload/src/main/webapp/WEB-INF/web.xml index 81f75941..d8d850cf 100644 --- a/file-upload/src/main/webapp/WEB-INF/web.xml +++ b/file-upload/src/main/webapp/WEB-INF/web.xml @@ -1,8 +1,10 @@ - + xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd" + metadata-complete="false" + version="6.0"> + Struts Blank diff --git a/file-upload/src/main/webapp/index.html b/file-upload/src/main/webapp/index.html deleted file mode 100644 index 89ec7f17..00000000 --- a/file-upload/src/main/webapp/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - -

Loading ...

- - diff --git a/sitemesh3/pom.xml b/sitemesh3/pom.xml index 7f31a857..5e553931 100644 --- a/sitemesh3/pom.xml +++ b/sitemesh3/pom.xml @@ -13,6 +13,10 @@ war + + 7.0.4-SNAPSHOT + + org.sitemesh diff --git a/sitemesh3/src/main/resources/struts.xml b/sitemesh3/src/main/resources/struts.xml index 935d1b82..7048cff6 100644 --- a/sitemesh3/src/main/resources/struts.xml +++ b/sitemesh3/src/main/resources/struts.xml @@ -8,7 +8,7 @@ - + /WEB-INF/index.jsp @@ -21,4 +21,14 @@ + + + + + /WEB-INF/admin/index.jsp + + + /WEB-INF/admin/hello.jsp + +
diff --git a/sitemesh3/src/main/webapp/WEB-INF/admin/hello.jsp b/sitemesh3/src/main/webapp/WEB-INF/admin/hello.jsp new file mode 100644 index 00000000..b3e711e3 --- /dev/null +++ b/sitemesh3/src/main/webapp/WEB-INF/admin/hello.jsp @@ -0,0 +1,14 @@ +<%@ page contentType="text/html; charset=UTF-8" %> +<%@ taglib prefix="s" uri="/struts-tags" %> + + + SiteMesh example: Admin Index + + +

SiteMesh example: Admin Index with Default Decorator

+ + + +Hello + + \ No newline at end of file diff --git a/sitemesh3/src/main/webapp/WEB-INF/admin/index.jsp b/sitemesh3/src/main/webapp/WEB-INF/admin/index.jsp new file mode 100644 index 00000000..b3e711e3 --- /dev/null +++ b/sitemesh3/src/main/webapp/WEB-INF/admin/index.jsp @@ -0,0 +1,14 @@ +<%@ page contentType="text/html; charset=UTF-8" %> +<%@ taglib prefix="s" uri="/struts-tags" %> + + + SiteMesh example: Admin Index + + +

SiteMesh example: Admin Index with Default Decorator

+ + + +Hello + + \ No newline at end of file