Structs2.1.6 HelloWorld

Structs配置

1,首先新建一个java web工程

2,将web.xml中添加filter,filter-mapping等字段。web.xml文件时在WEB-INF目录下的(从apps sample里面寻找web.xml直接复制copy)

3,将structs.xml文件拷入src目录下,修改<action><result>这些字段。

4,将structs的依赖包copy到lib目录下。

web.xml

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

structs.xml

<package name="default" namespace="/" extends="struts-default">
        <action name="hello">
            <result>
               /Hello.jsp
            </result>
        </action>
        
</package>

 小技巧:

         在xml文件中配置提示 window-prefence-Xml catlog

         key_type:URI

         key:http://struts.apache.org/dtds/struts-2.0.dtd

         location:寻找lib目录下app,解压war包,寻找structs-core-2.1.6.jar这个包,找到dtd这个文件

structs整个访问流程

首先请求交给tomcat,tomcat查找是哪一个web application,查找到之后查看web.xml的filter,匹配对应的类,交由org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter类处理,这个类会参考struct.xml文件来确定 namespace-->action-->result,最后由result指定的文件返回结果。

Hello Structs

posted on 2014-07-11 10:41  Champion Lai  阅读(296)  评论(0编辑  收藏  举报

导航