• Struts2(1) —— 概述


    1、Struts2框架介绍

    Struts2框架是MVC流程框架,适合分层开发,框架应用实现不依赖于Servlet,使用大量的拦截器来处理用户请求,属于无侵入式的设计。

    2、Struts2框架的流程原理

    1)请求先到达Filter中央控制器;

    2)然后为Action创建代理类;

    3)将各个服务存放在拦截器中,执行完拦截器后再去执行action类,action类调用service,再调用dao;

    4)得到结果字符串,创建result对象;

    5)转向相应的视图。

    3、框架的使用

      框架为我们做好了封装,使用起来就按照步骤,配置几个xml文件就好。

      1)导入jar包

      2)拷贝struts.xml文件。

      将拷贝的配置文件放在根目录src下。struts.xml文件主要是配置请求路径对应action类的,以及结果跳转路劲。

        <?xml version="1.0" encoding="UTF-8" ?>  
        <!DOCTYPE struts PUBLIC  
            "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"  
            "http://struts.apache.org/dtds/struts-2.0.dtd">  
        <struts>  
            <package name="example" namespace="/example" extends="struts-default">  
                <action name="HelloWorld" class="struts2.action.HelloWorldAction">  
                    <result name="success">/success.jsp</result>  
                </action>  
            </package>      
        </struts>  
    

       代码说明:访问/example/HelloWorld.action对应执行struts2.action包下面的HelloWorldAction类;默认情况下执行类中的execute方法,如果想指定方法,需要在<action>标签中添加method属性;<result>标签配置结果跳转路径。根据Action类中方法返回的String字符串,去匹配result标签中的name值,进行跳转。

       

      3)在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>  
    

      

  • 相关阅读:
    vue 父子组件通信props/emit
    mvvm
    Ajax
    闭包
    【CSS3】---only-child选择器+only-of-type选择器
    【CSS3】---last-of-type选择器+nth-last-of-type(n)选择器
    【CSS3】---first-of-type选择器+nth-of-type(n)选择器
    【CSS3】---结构性伪类选择器—nth-child(n)+nth-last-child(n)
    【CSS3】---结构性伪类选择器-first-child+last-child
    vue路由切换和用location切换url的区别
  • 原文地址:https://www.cnblogs.com/nin-w/p/6086599.html
Copyright © 2020-2023  润新知