构建新版本的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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

随风而行无疾而歌

看官,觉得不错,奖励一下呗

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值