Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions file-upload/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
<webApp>
<contextPath>/${project.artifactId}</contextPath>
</webApp>
<stopKey>CTRL+C</stopKey>
<stopPort>8999</stopPort>
<scanIntervalSeconds>10</scanIntervalSeconds>
<scan>10</scan>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
* <code>Allows upload a file</code>
*/
public class Upload extends ActionSupport {
public class UploadAction extends ActionSupport implements UploadedFilesAware {

private File[] upload;
private String[] uploadFileName;
Expand All @@ -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<UploadedFile> 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);
}
}
13 changes: 9 additions & 4 deletions file-upload/src/main/resources/struts.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"https://struts.apache.org/dtds/struts-2.5.dtd">
"-//Apache Software Foundation//DTD Struts Configuration 6.0//EN"
"https://struts.apache.org/dtds/struts-6.0.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false"/>
<constant name="struts.devMode" value="true"/>
Expand All @@ -12,11 +12,16 @@

<action name="index">
<result type="redirectAction">
<param name="actionName">upload</param>
<param name="actionName">input</param>
</result>
</action>

<action name="upload" class="org.apache.struts.example.Upload">
<action name="input" class="org.apache.struts.example.UploadAction">
<result name="input">WEB-INF/input.jsp</result>
</action>

<action name="upload" class="org.apache.struts.example.UploadAction" method="upload">
<result>WEB-INF/upload.jsp</result>
<result name="input">WEB-INF/upload.jsp</result>
</action>

Expand Down
20 changes: 20 additions & 0 deletions file-upload/src/main/webapp/WEB-INF/input.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>File upload: input</title>
</head>

<body>

<s:form action="upload" method="post" enctype="multipart/form-data">
<s:file name="upload"/>
<s:file name="upload"/>
<s:file name="upload"/>
<s:submit/>
</s:form>

<s:actionerror/>

</body>
</html>
13 changes: 6 additions & 7 deletions file-upload/src/main/webapp/WEB-INF/upload.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>File upload</title>
<title>File upload: result</title>
</head>

<body>

<s:form action="upload" method="post" enctype="multipart/form-data">
<s:file name="upload"/>
<s:file name="upload"/>
<s:file name="upload"/>
<s:submit/>
</s:form>
<p>
<s:a action="input">back to input</s:a>
</p>

<s:actionerror/>

<s:iterator value="upload" var="u">
<s:property value="u"/><br/>
Expand Down
8 changes: 5 additions & 3 deletions file-upload/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="struts_blank" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
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">

<display-name>Struts Blank</display-name>

<filter>
Expand Down
10 changes: 0 additions & 10 deletions file-upload/src/main/webapp/index.html

This file was deleted.

4 changes: 4 additions & 0 deletions sitemesh3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

<packaging>war</packaging>

<properties>
<struts2.version>7.0.4-SNAPSHOT</struts2.version>
</properties>

<dependencies>
<dependency>
<groupId>org.sitemesh</groupId>
Expand Down
12 changes: 11 additions & 1 deletion sitemesh3/src/main/resources/struts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<constant name="struts.action.extension" value=""/>
<constant name="struts.custom.i18n.resources" value="DefaultMessages"/>

<package name="default" extends="struts-default">
<package name="default" extends="struts-default" namespace="/">
<default-action-ref name="index"/>
<action name="index">
<result>/WEB-INF/index.jsp</result>
Expand All @@ -21,4 +21,14 @@
</action>

</package>

<package name="default2" extends="struts-default" namespace="/admin">
<default-action-ref name="index"/>
<action name="index">
<result>/WEB-INF/admin/index.jsp</result>
</action>
<action name="hello">
<result>/WEB-INF/admin/hello.jsp</result>
</action>
</package>
</struts>
14 changes: 14 additions & 0 deletions sitemesh3/src/main/webapp/WEB-INF/admin/hello.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>SiteMesh example: Admin Index</title>
</head>
<body>
<h2>SiteMesh example: Admin Index with Default Decorator</h2>
<s:url var="url" action="hello" namespace="/">
<s:param name="decorator" value="1"/>
</s:url>
<s:a href="%{url}">Hello</s:a>
</body>
</html>
14 changes: 14 additions & 0 deletions sitemesh3/src/main/webapp/WEB-INF/admin/index.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>SiteMesh example: Admin Index</title>
</head>
<body>
<h2>SiteMesh example: Admin Index with Default Decorator</h2>
<s:url var="url" action="hello" namespace="/">
<s:param name="decorator" value="1"/>
</s:url>
<s:a href="%{url}">Hello</s:a>
</body>
</html>