struts2 入门

下载struts2:http://struts.apache.org/2.x/ 

搭建struts2项目

1.导入struts2所需jar包(struts2 jar包说明)

2.编辑Web应用的web.xml配置文件,配置Struts 2的核心Filter。

View Code
<filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

     <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

3.创建struts.xml文件(struts.xml详解1struts.xml详解2)

4.创建Action类,添加execute方法。要继承com.opensymphony.xwork2.ActionSupport 类或者其他已经继承此类的类

5.在struts.xml文件中配置action

View Code
<action name="hello" class="org.apache.struts.helloworld.action.HelloWorldAction" method="execute">
            <result name="success">/HelloWorld.jsp</result>
        </action>

另外struts的官网提供了很多例子,有空白项目,也有演示功能的demo。

下载struts2例子:http://code.google.com/p/struts2-examples/downloads/list

原文地址:https://www.cnblogs.com/nami/p/2675335.html