strtus_1

使用struts2需要步骤

1.配置struts的filter

    <filter>
        <filter-name>struts2</filter-name>
        <!--filter对应的类全路径-->
        <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
        <!--filter所能过滤的范围-->
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <!--过滤器所拦截的路径-->
        <url-pattern>/*</url-pattern>
    </filter-mapping>
StrutsPrepareAndExecuteFilter类中
  init函数:读取struts的配置资源和常量资源
  destory:销毁占用的资源
  dofilter:struts执行方法响应请求

在web.xml中配置

2.编写action

action是控制层,编写struts2具体实现类都是xxxAction,struts2中的action可以不继承任何父类或实现任何接口,struts2的默认访问函数为无参的execute,改execute必须返回String类型的返回值,struts框架会根据返回值在配置文件中读取action执行后显示的jsp

3.编写配置文件

4.编写jsp文件

  action的路径是../namespace + “/” + action类名

posted on 2018-06-01 10:57  fionalde  阅读(87)  评论(0编辑  收藏  举报