1、环境搭建

1、在pom.xml导入相应的jar包:struts2-core

2、设置web.xml添加struts2的过滤器:

1   <filter>
2         <filter-name>struts2</filter-name>
3         <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
4     </filter>
5 
6     <filter-mapping>
7         <filter-name>struts2</filter-name>
8         <url-pattern>/*</url-pattern>
9     </filter-mapping>

3、创建相应的action类(写一个execute方法,并返回一个字符串)

1 public void HelloAction{
2     public String execute(){
3         System.out.println("Hello Action");
4         return "success";
5     }
6 }

4、编写struts2.xml文件

<struts>
    <package name="default" namespace="/" extends="struts-default">
    <action name="hello" class="action.HelloAction">
            <result name="success">/index.jsp</result>
        </action>
</struts>

 

posted @ 2015-11-20 14:51  Akke  阅读(137)  评论(0编辑  收藏  举报