• 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>

    第六步:部署运行
     
     
     


  • 相关阅读:
    基于MATLAB求解矩阵的正交补矩阵
    MySQL的安装与配置
    删除ubuntu后修复win7系统的引导
    VS2010中快捷添加命名空间
    java学习之函数
    java学习之break 和 continue
    For循环复杂练习
    For循环练习之99乘法表和转义字符
    java学习之语句结构
    java学习之运算符
  • 原文地址:https://www.cnblogs.com/sujulin/p/8470049.html
Copyright © 2020-2023  润新知