zoukankan      html  css  js  c++  java
  • struts2实验02 单文件上传, 多文件上传, 文件下载

    1、IDEA创建一个maven项目, 项目结构为:

    .
    ├── FileUpload.iml
    ├── pom.xml
    ├── src
    │   └── main
    │       ├── java
    │       │   └── shiyanlou
    │       │       └── struts
    │       │           ├── DownloadAction.java
    │       │           ├── MultiUploadAction.java
    │       │           └── UploadAction.java
    │       ├── resources
    │       │   └── struts.xml
    │       └── webapp
    │           ├── WEB-INF
    │           │   └── web.xml
    │           ├── error.jsp
    │           ├── index.jsp
    │           ├── success.jsp
    │           ├── uploadFiles
    │           │   └── test2.txt
    │           └── uploadMultiFiles
    │               ├── test.txt
    │               └── test2.txt

    2、在pom.xml中引入项目依赖, strtus2和servlet, 服务器容器为jetty

    <?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>
    
        <groupId>org.example</groupId>
        <artifactId>FileUpload</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>war</packaging>
    
    
        <dependencies>
            <dependency>
                <groupId>org.apache.struts</groupId>
                <artifactId>struts2-core</artifactId>
                <version>2.5.18</version>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
                <version>4.0.1</version>
                <scope>provided</scope>
            </dependency>
    
        </dependencies>
    
        <build>
            <finalName>FileUpload</finalName>
            <plugins>
                <plugin>
                    <groupId>org.eclipse.jetty</groupId>
                    <artifactId>jetty-maven-plugin</artifactId>
                    <version>9.4.12.v20180830</version>
                    <configuration>
                        <scanIntervalSeconds>10</scanIntervalSeconds>
                        <webApp>
                            <contextPath>/</contextPath>
                        </webApp>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    
    </project>

    3、web.xml : 设置web项目的结构, 引入struts拦截器, 所有的URL的请求都必须通过struts

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
             xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
             id="WebApp_ID" version="3.0">
        <display-name>FileUpload</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>index.htm</welcome-file>
            <welcome-file>index.jsp</welcome-file>
            <welcome-file>default.html</welcome-file>
            <welcome-file>default.htm</welcome-file>
            <welcome-file>default.jsp</welcome-file>
        </welcome-file-list>
    
    </web-app>

    4、

  • 相关阅读:
    HDU 5640 King's Cake
    HDU 5615 Jam's math problem
    HDU 5610 Baby Ming and Weight lifting
    WHU1604 Play Apple 简单博弈
    HDU 1551 Cable master 二分
    CodeForces659C Tanya and Toys map
    Codeforces 960E 树dp
    gym 101485E 二分匹配
    Codeforces 961E 树状数组,思维
    Codeforces Round #473 (Div. 2) D 数学,贪心 F 线性基,模板
  • 原文地址:https://www.cnblogs.com/huangZ-H/p/12247457.html
Copyright © 2011-2022 走看看