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>

    第六步:部署运行
     
     
     


  • 相关阅读:
    电商网站测试总结
    web测试总结—用户体验
    测试用例的常用方法
    linux系统中如何查看日志 (常用命令)
    web与app测试的区别
    Json模块dumps、loads、dump、load函数介绍
    postman—集成到jenkins
    Postman—命令执行脚本及生成报告
    Postman—测试脚本
    Postman—前置请求脚本
  • 原文地址:https://www.cnblogs.com/sujulin/p/8470049.html
Copyright © 2011-2022 走看看