Java ee第四周作业
代碼下載鏈接:https://github.com/javaee/tutorial-examples/tree/master/web/jsf/hello1
代碼內容:
/**
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
*
* You may not modify, use, reproduce, or distribute this software except in
* compliance with the terms of the License at:
* https://github.com/javaee/tutorial-examples/LICENSE.txt
*/
package javaeetutorial.hello1;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
@Named
@RequestScoped
public class Hello {
private String name;
public Hello() {
}
public String getName() {
return name;
}
public void setName(String user_name) {
this.name = user_name;
}
}
?
代碼分析:
?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應用程序的交互中持久存在。
轉載于:https://www.cnblogs.com/vonzc/p/8692505.html
總結
以上是生活随笔為你收集整理的Java ee第四周作业的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SpringSecurity csrf验
- 下一篇: windows使用Win32DiskIm