构建新版本的SSI项目(Sturts2 Spring Ibatis(mybatis)) 第一篇 Sturts2-2.5版本的 搭建框架

搭建Sturts2-2.5版本 框架

开发环境准备:jdk8.0或以上版本,IDEA2017版本,tomcat7.0或以上

1、首先导入需要的jar包:

让项目识别到jar包:

点击ok:

对应的lib打勾,点击apply,点击ok,接下来就是设置配置文件了:

2、首先是web.xml设置如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
    <filter>
        <filter-name>action2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <!-- END SNIPPET: filter -->
    <filter-mapping>
        <filter-name>action2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>


</web-app>

3、配置struts.xml

在src目录下,新建文件struts.xml文件,配置如下:

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



    <package name="default" extends="struts-default">
        <!--<global-allowed-methods>hello</global-allowed-methods>-->
        <action name="hello" class="meng.MengAction">
            <result name="success">/MyTest.jsp</result>
        </action>
    </package>

</struts>

4、新建测试类:

代码:

package meng;

import com.opensymphony.xwork2.ActionSupport;

public class MengAction extends ActionSupport{

    public String getLive() {
        System.out.println("为了变瘦");
        return SUCCESS;
    }
}

5.新建测试jsp:

<%--
  Created by IntelliJ IDEA.
  User: lvzhihao
  Date: 2018/7/26
  Time: 15:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>喜欢上你</title>
</head>
<body>
我一定会追到你
</body>
</html>

6、测试结果:

输入http://localhost:8080/SsiNewTest/hello

至此Struts2.5搭建架构完成,提供个Sturts官方下载网址http://struts.apache.org/download.cgi#struts2516

猜你喜欢

转载自blog.csdn.net/qq_38000902/article/details/81205473