zoukankan      html  css  js  c++  java
  • Java EE第四周

     1 /**
     2  * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
     3  *
     4  * You may not modify, use, reproduce, or distribute this software except in
     5  * compliance with  the terms of the License at:
     6  * https://github.com/javaee/tutorial-examples/LICENSE.txt
     7  */
     8 package javaeetutorial.hello1;
     9 
    10 
    11 import javax.enterprise.context.RequestScoped;
    12 import javax.inject.Named;
    13 
    14 @Named
    15 @RequestScoped
    16 public class Hello {
    17 
    18     private String name;
    19 
    20     public Hello() {
    21     }
    22 
    23     public String getName() {
    24         return name;
    25     }
    26 
    27     public void setName(String user_name) {
    28         this.name = user_name;
    29     }
    30 }
    复制代码
    复制代码

            Hello类叫做管理bean类,它为facelets页面表达式所使用的name属性提供了getter和setter方法,默认该facelets页面表达式引用的是Hello类的名字,不过第一个字母是小写字母(例如:hello.name)。

           在 Hello.java类中,注解javax.inject.Named和javax.enterprise.context.RequestScoped使用请求scope来标识Hello类为管理bean类。scope定义应用程序数据是如何保存和共享的。

          在JSF中最常用的scope如下:

                     Request(@RequestScoped):请求scope在Web应用程序中的单个HTTP请求期间仍然存在。像hello1应用,该应用由单个请求和响应组成,bean使用请求scope。

                     Session (@SessionScoped):会话scope持续存在于Web应用程序中的多个HTTP请求中。当应用程序包含需要维护数据的多个请求和响应时,bean使用会话scope。 

                     Application (@ApplicationScoped):应用程序scope在所有用户与Web应用程序的交互中持久存在。

  • 相关阅读:
    「2019.7.25 考试」偶然发生
    「刷题」可怜与STS
    「刷题」小星星
    「刷题」数三角形
    「刷题」 关于线段上的整点个数
    「刷题」Color 群论
    「2019.7.22 考试」AC和WA0一步之遥
    「刷题」幸运数字
    「刷题」卡特兰数&prufer序列
    「刷题」一个人的数论
  • 原文地址:https://www.cnblogs.com/wangshisan/p/8705816.html
Copyright © 2011-2022 走看看