Struts2.之HelloWorld简单演示

来源:互联网 发布:用友网络 编辑:程序博客网 时间:2024/05/20 20:44

新建一个web project:hello-struts

这里写图片描述

1.拷贝struts的jar包到项目中(apps中的blank项目中可以找到这些jar包)

这里写图片描述

2.讲struts2的过滤器拷贝到web.xml中

这里写图片描述

3.配置struts2的配置文件(在src目录中创建struts.xml文件)

这里写图片描述

4.创建action(action就是一个POJO类)

这里写图片描述

  • 4.1 为action编写execute方法
    public String execute(){        System.out.println("Hello struts.");        return "success";    }
  • 4.2 在struts.xml文件中配置action和返回结果集
<action name="hello" class="net.qbzhong.action.HelloAction"            method="execute">            <result name="success">/hello.jsp</result>        </action>

直接运行,进入index.jsp页面

这里写图片描述

在地址栏后面加上hello,进入hello.jsp

这里写图片描述

0 0
原创粉丝点击