struts2是多例的

 

验证代码:主要看构造器会执行多少次

//Action类

public class Hello {
    public Hello(){
        System.out.println("Struts2是多例的 而 servlet是单例的 servlet的 init永远只执行一次 service每次请求都会执行");
    }

    public String hell(){
        System.out.println("hello..................");
        return "h";
    }
}

//配置类
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "struts-2.1.dtd" >
<struts>

    <package name="xxxxx" extends="struts-default" namespace="/">
        <action name="helloWorld" class="com.cn.Hello" method="hell">
            <result name="h" type="redirect" >/index.jsp</result>
        </action>
    </package>
    

</struts>

//测试结果

http://localhost:8080/Re_Servlet/helloWorld   执行多少次这个url请求 构造器就会构造出多少个对象!!!!

 

 

 

 

posted @ 2020-05-28 15:43  gaoshengjun  阅读(151)  评论(0编辑  收藏  举报