zoukankan      html  css  js  c++  java
  • Struts的基础案例的步骤

    第一步:引入依赖

    <!--struts2 核心包-->
    <!-- https://mvnrepository.com/artifact/org.apache.struts/struts2-core -->
    <dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-core</artifactId>
    <version>2.3.4</version>
    </dependency>

    <!--xwork 核心包-->
    <!-- https://mvnrepository.com/artifact/org.apache.struts.xwork/xwork-core -->
    <dependency>
    <groupId>org.apache.struts.xwork</groupId>
    <artifactId>xwork-core</artifactId>
    <version>2.3.4</version>
    </dependency>

    <dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>7.0</version>
    <scope>provided</scope>
    </dependency>

    第二步:配置web.xml文件
    <filter>
    <filter-name>struts</filter-name>
    <!--核心控制器-->
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
    <filter-name>struts</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    第三步:view视图
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
    <title></title>
    </head>
    <body>
    <h2> struts hello </h2>
    </body>
    </html>

    第四步:定制Action
    public class HelloAction  implements Action{
    //执行 返回值
    public String execute() throws Exception {
    System.out.println("=====================code execute here ,it will render hello.jsp=======================");
    return SUCCESS;
    }
    }

    第五步:struts.xml  在resources文件夹下定义一个名称为struts.xml的文件
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">
    <struts>
    <package name="default" namespace="/" extends="struts-default">
            <!--第一个demo-->
    <action name="hello" class="cn.sjl.day01.controller.HelloAction">
    <result name="success">hello.jsp</result>
    </action>
    </package>
    </struts>

    第六步:部署运行
     
     
     


  • 相关阅读:
    原来这才是 Socket !
    C 语言基础,来喽!
    手把手教你汇编 Debug
    拒做技术小白?计算机关键概念你不得不掌握!
    利用Windbg分析Magicodes.IE一次错误编写导致内存剧增
    Spring Boot整合JApiDocs实现API文档
    Spring Boot 快速整合Swagger
    Python测试框架pytest入门基础
    性能测试之测试分析与调优
    html5调用摄像头截图
  • 原文地址:https://www.cnblogs.com/sujulin/p/8470049.html
Copyright © 2011-2022 走看看