Repository: struts-examples Updated Branches: refs/heads/master 4264f901c -> d4619afd2
Adds simple file upload example Project: http://git-wip-us.apache.org/repos/asf/struts-examples/repo Commit: http://git-wip-us.apache.org/repos/asf/struts-examples/commit/d4619afd Tree: http://git-wip-us.apache.org/repos/asf/struts-examples/tree/d4619afd Diff: http://git-wip-us.apache.org/repos/asf/struts-examples/diff/d4619afd Branch: refs/heads/master Commit: d4619afd2709c85c7a7b4deee4166bde72498bee Parents: 4264f90 Author: Lukasz Lenart <lukasz.len...@gmail.com> Authored: Tue Nov 22 09:45:37 2016 +0100 Committer: Lukasz Lenart <lukasz.len...@gmail.com> Committed: Tue Nov 22 09:45:37 2016 +0100 ---------------------------------------------------------------------- file-upload/pom.xml | 40 ++++++++++++ .../java/org/apache/struts/example/Upload.java | 64 ++++++++++++++++++++ file-upload/src/main/resources/log4j2.xml | 15 +++++ file-upload/src/main/resources/struts.xml | 26 ++++++++ file-upload/src/main/webapp/WEB-INF/upload.jsp | 28 +++++++++ file-upload/src/main/webapp/WEB-INF/web.xml | 23 +++++++ file-upload/src/main/webapp/index.html | 10 +++ pom.xml | 1 + 8 files changed, 207 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/struts-examples/blob/d4619afd/file-upload/pom.xml ---------------------------------------------------------------------- diff --git a/file-upload/pom.xml b/file-upload/pom.xml new file mode 100644 index 0000000..b83e398 --- /dev/null +++ b/file-upload/pom.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <artifactId>struts-examples</artifactId> + <groupId>org.apache.struts</groupId> + <version>1.0.0</version> + </parent> + + <artifactId>file-upload</artifactId> + + <name>File upload</name> + <description>Simple file upload example</description> + <packaging>war</packaging> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <build> + <plugins> + <plugin> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty-maven-plugin</artifactId> + <version>8.1.16.v20140903</version> + <configuration> + <stopKey>CTRL+C</stopKey> + <stopPort>8999</stopPort> + <scanIntervalSeconds>10</scanIntervalSeconds> + <webAppSourceDirectory>${basedir}/src/main/webapp/</webAppSourceDirectory> + <webAppConfig> + <descriptor>${basedir}/src/main/webapp/WEB-INF/web.xml</descriptor> + </webAppConfig> + </configuration> + </plugin> + </plugins> + </build> +</project> http://git-wip-us.apache.org/repos/asf/struts-examples/blob/d4619afd/file-upload/src/main/java/org/apache/struts/example/Upload.java ---------------------------------------------------------------------- diff --git a/file-upload/src/main/java/org/apache/struts/example/Upload.java b/file-upload/src/main/java/org/apache/struts/example/Upload.java new file mode 100644 index 0000000..a10c83d --- /dev/null +++ b/file-upload/src/main/java/org/apache/struts/example/Upload.java @@ -0,0 +1,64 @@ +/* + * $Id$ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.struts.example; + +import com.opensymphony.xwork2.ActionSupport; + +import java.io.File; + +/** + * <code>Allows upload a file</code> + */ +public class Upload extends ActionSupport { + + private File[] upload; + private String[] uploadFileName; + private String[] uploadContentType; + + public String execute() throws Exception { + return INPUT; + } + + public File[] getUpload() { + return upload; + } + + public void setUpload(File[] upload) { + this.upload = 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; + } +} http://git-wip-us.apache.org/repos/asf/struts-examples/blob/d4619afd/file-upload/src/main/resources/log4j2.xml ---------------------------------------------------------------------- diff --git a/file-upload/src/main/resources/log4j2.xml b/file-upload/src/main/resources/log4j2.xml new file mode 100644 index 0000000..092d5f6 --- /dev/null +++ b/file-upload/src/main/resources/log4j2.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Configuration> + <Appenders> + <Console name="STDOUT" target="SYSTEM_OUT"> + <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/> + </Console> + </Appenders> + <Loggers> + <Logger name="com.opensymphony.xwork2" level="info"/> + <Logger name="org.apache.struts2" level="info"/> + <Root level="warn"> + <AppenderRef ref="STDOUT"/> + </Root> + </Loggers> +</Configuration> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/struts-examples/blob/d4619afd/file-upload/src/main/resources/struts.xml ---------------------------------------------------------------------- diff --git a/file-upload/src/main/resources/struts.xml b/file-upload/src/main/resources/struts.xml new file mode 100644 index 0000000..2e012c6 --- /dev/null +++ b/file-upload/src/main/resources/struts.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE struts PUBLIC + "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" + "http://struts.apache.org/dtds/struts-2.5.dtd"> +<struts> + <constant name="struts.enable.DynamicMethodInvocation" value="false"/> + <constant name="struts.devMode" value="true"/> + + <package name="default" namespace="/" extends="struts-default"> + + <default-action-ref name="index"/> + + <action name="index"> + <result type="redirectAction"> + <param name="actionName">upload</param> + </result> + </action> + + <action name="upload" class="org.apache.struts.example.Upload"> + <result name="input">WEB-INF/upload.jsp</result> + </action> + + </package> + + <!-- Add addition packages and configuration here. --> +</struts> http://git-wip-us.apache.org/repos/asf/struts-examples/blob/d4619afd/file-upload/src/main/webapp/WEB-INF/upload.jsp ---------------------------------------------------------------------- diff --git a/file-upload/src/main/webapp/WEB-INF/upload.jsp b/file-upload/src/main/webapp/WEB-INF/upload.jsp new file mode 100644 index 0000000..247293a --- /dev/null +++ b/file-upload/src/main/webapp/WEB-INF/upload.jsp @@ -0,0 +1,28 @@ +<%@ page contentType="text/html; charset=UTF-8" %> +<%@ taglib prefix="s" uri="/struts-tags" %> +<html> +<head> + <title>File upload</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:iterator value="upload" var="u"> + <s:property value="u"/><br/> +</s:iterator> +<s:iterator value="uploadContentType" var="ct"> + <s:property value="ct"/><br/> +</s:iterator> +<s:iterator value="uploadFileName" var="fn"> + <s:property value="fn"/><br/> +</s:iterator> + +</body> +</html> http://git-wip-us.apache.org/repos/asf/struts-examples/blob/d4619afd/file-upload/src/main/webapp/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/file-upload/src/main/webapp/WEB-INF/web.xml b/file-upload/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..81f7594 --- /dev/null +++ b/file-upload/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<web-app id="struts_blank" version="2.4" + xmlns="http://java.sun.com/xml/ns/j2ee" + 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"> + <display-name>Struts Blank</display-name> + + <filter> + <filter-name>struts2</filter-name> + <filter-class> + org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter + </filter-class> + </filter> + + <filter-mapping> + <filter-name>struts2</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> + + <welcome-file-list> + <welcome-file>index.html</welcome-file> + </welcome-file-list> +</web-app> http://git-wip-us.apache.org/repos/asf/struts-examples/blob/d4619afd/file-upload/src/main/webapp/index.html ---------------------------------------------------------------------- diff --git a/file-upload/src/main/webapp/index.html b/file-upload/src/main/webapp/index.html new file mode 100644 index 0000000..89ec7f1 --- /dev/null +++ b/file-upload/src/main/webapp/index.html @@ -0,0 +1,10 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> +<html> +<head> + <META HTTP-EQUIV="Refresh" CONTENT="0;URL=upload.action"> +</head> + +<body> +<p>Loading ...</p> +</body> +</html> http://git-wip-us.apache.org/repos/asf/struts-examples/blob/d4619afd/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 0b262e6..bef3bc8 100644 --- a/pom.xml +++ b/pom.xml @@ -52,6 +52,7 @@ <module>debugging-struts</module> <module>exception-handling</module> <module>exclude-parameters</module> + <module>file-upload</module> <module>form-processing</module> <module>form-tags</module> <module>form-validation</module>