{"id":751,"date":"2023-03-29T16:36:02","date_gmt":"2023-01-05T06:11:38","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/index.php\/2023\/11\/30\/jsf-%e9%9d%a2%e8%af%95%e9%97%ae%e9%a2%98%e4%b8%8e%e5%9b%9e%e7%ad%94\/"},"modified":"2025-08-03T06:16:14","modified_gmt":"2025-08-02T22:16:14","slug":"jsf-%e9%9d%a2%e8%af%95%e9%97%ae%e9%a2%98%e4%b8%8e%e5%9b%9e%e7%ad%94","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/jsf-%e9%9d%a2%e8%af%95%e9%97%ae%e9%a2%98%e4%b8%8e%e5%9b%9e%e7%ad%94\/","title":{"rendered":"2023\u6700\u65b0JSF(JavaServer Faces)\u9762\u8bd5\u9898\u4e0e\u7b54\u6848\u5927\u5168 &#8211; Java\u5f00\u53d1\u5fc5\u5907\u6307\u5357"},"content":{"rendered":"<p>\u6700\u8fd1\u6211\u64b0\u5199\u4e86\u8bb8\u591a\u5173\u4e8eJSF\u6846\u67b6\u7684\u5185\u5bb9\uff0c\u56e0\u6b64\u73b0\u5728\u6b63\u662f\u6574\u7406\u4e00\u7bc7\u5173\u4e8eJSF\u9762\u8bd5\u95ee\u9898\u4e0e\u7b54\u6848\u6587\u7ae0\u7684\u597d\u65f6\u673a\u3002\u4ee5\u4e0b\u662f\u6211\u7cbe\u5fc3\u6536\u96c6\u7684JSF\u9762\u8bd5\u95ee\u9898\u4e0e\u7b54\u6848\u3002\u5efa\u8bae\u5728\u9762\u8bd5\u524d\u4ed4\u7ec6\u9605\u8bfb\u8fd9\u4e9b\u95ee\u9898\uff0c\u6211\u76f8\u4fe1\u8fd9\u5c06\u5e2e\u52a9\u4f60\u987a\u5229\u901a\u8fc7JSF\u9762\u8bd5\u5e76\u6210\u529f\u83b7\u5f97\u5de5\u4f5c\u673a\u4f1a\u3002\u8bf7\u6ce8\u610f\uff0c\u8fd9\u4e9b\u95ee\u9898\u4e3b\u8981\u9488\u5bf9JSF 2\u7248\u672c\uff0c\u800c\u975eJSF 1\u3002<\/p>\n<h2>JSF \u9762\u8bd5\u95ee\u9898<\/h2>\n<ol>\n<li>JSF\u662f\u4ec0\u4e48\uff1f<\/li>\n<li>\u6258\u7ba1Bean\u662f\u4ec0\u4e48\uff1f<\/li>\n<li>JSF\u63d0\u4f9b\u4e86\u54ea\u4e09\u79cd\u7c7b\u578b\u7684\u6587\u672c\u5b57\u6bb5\u6807\u7b7e\uff1f<\/li>\n<li>@ManagedProperty\u6ce8\u91ca\u7684\u91cd\u8981\u6027\u662f\u4ec0\u4e48\uff1f<\/li>\n<li>@ApplicationScoped\u6ce8\u91ca\u8868\u793a\u4ec0\u4e48\uff1f<\/li>\n<li>JSF\u4e2d\u7684\u8d44\u6e90\u7ed1\u5b9a\u662f\u4ec0\u4e48\uff1f<\/li>\n<li>\u89e3\u91ca\u6807\u7b7e\u7684required\u548crequiredMessage\u5c5e\u6027\uff1f<\/li>\n<li>JSF\u652f\u6301\u54ea\u4e9b\u4e0d\u540c\u7c7b\u578b\u7684\u9875\u9762\u5bfc\u822a\uff1f<\/li>\n<li>JSF\u7684\u751f\u547d\u5468\u671f\u9636\u6bb5\u662f\u4ec0\u4e48\uff1f<\/li>\n<li>\u89e3\u91ca\u6807\u7b7e\u7684\u4e00\u4e9b\u5c5e\u6027\uff1f<\/li>\n<li>\u7528\u4e8e\u64cd\u4f5c\u548c\u5bfc\u822a\u7684\u547d\u4ee4\u7ec4\u4ef6\u6807\u7b7e\u6709\u54ea\u4e9b\uff1f<\/li>\n<li>\u4ec0\u4e48\u662f\u6570\u636e\u7ed1\u5b9a\u8868\u683c\u7ec4\u4ef6\uff1f<\/li>\n<li>\u4ec0\u4e48\u662f\u4e8b\u4ef6\uff1f<\/li>\n<li>\u5982\u4f55\u83b7\u53d6\u751f\u6210\u7684\u4e8b\u4ef6\uff1f<\/li>\n<li>JSF\u6709\u54ea\u4e9b\u4e0d\u540c\u7c7b\u578b\u7684\u4e8b\u4ef6\uff1f<\/li>\n<li>\u4ec0\u4e48\u662f\u76d1\u542c\u5668\u7c7b\uff1f<\/li>\n<li>facelets\u6807\u7b7e\u7684\u91cd\u8981\u6027\u662f\u4ec0\u4e48\uff1f<\/li>\n<li>\u4e00\u4e9bfacelets\u6807\u7b7e\u6709\u54ea\u4e9b\uff1f<\/li>\n<li>JSF\u4e2d\u7684\u9a8c\u8bc1\u6709\u54ea\u4e9b\u4e0d\u540c\u7c7b\u578b\uff1f<\/li>\n<li>JSF EL\u652f\u6301\u54ea\u4e9b\u4e0d\u540c\u7c7b\u578b\u7684\u8868\u8fbe\u5f0f\uff1f<\/li>\n<li>\u4ec0\u4e48\u662f\u5373\u65f6\u548c\u5ef6\u8fdf\u503c\u8868\u8fbe\u5f0f\uff1f<\/li>\n<li>\u89e3\u91ca\u503c\u8868\u8fbe\u5f0f\u548c\u65b9\u6cd5\u8868\u8fbe\u5f0f\uff1f<\/li>\n<li>\u89e3\u91ca@ViewScoped\u3001@SessionScoped\u3001@CustomScoped\u548c@RequestScoped\u6ce8\u91ca\uff1f<\/li>\n<li>\u5728JSF\u4e2d\u58f0\u660e\u6258\u7ba1Bean\u7684\u4e0d\u540c\u65b9\u5f0f\u6709\u54ea\u4e9b\uff1f<\/li>\n<li>\u6258\u7ba1Bean\u4e2dname\u548ceager\u5c5e\u6027\u7684\u91cd\u8981\u6027\u662f\u4ec0\u4e48\uff1f<\/li>\n<li>JSF\u4e2d\u4f7f\u7528\u7684\u4e00\u4e9b\u9a8c\u8bc1\u5668\u6807\u7b7e\u6709\u54ea\u4e9b\uff1f<\/li>\n<li>\u4f7f\u7528JSF\u6846\u67b6\u7684\u597d\u5904\u662f\u4ec0\u4e48\uff1f<\/li>\n<li>JSF\u8f6c\u6362\u5668\u6807\u7b7e\u6709\u54ea\u4e9b\u4e0d\u540c\u7684\u7c7b\u578b\uff1f<\/li>\n<li>\u5217\u4e3e\u8868\u8fbe\u5f0f\u8bed\u8a00\uff08EL\uff09\u7684\u597d\u5904\uff1f<\/li>\n<li>\u4ec0\u4e48\u662f\u540e\u7aefBean\uff1f<\/li>\n<li>\u4ec0\u4e48\u662f\u6807\u51c6JSF\u6807\u7b7e\u5e93\uff1f<\/li>\n<li>\u540e\u7aefBean\u65b9\u6cd5\u6267\u884c\u4e86\u54ea\u4e9b\u529f\u80fd\uff1f<\/li>\n<li>JSF API\u7684\u4e0d\u540c\u5b9e\u73b0\u6709\u54ea\u4e9b\uff1f<\/li>\n<li>\u89e3\u91caJSF\u67b6\u6784\uff1f<\/li>\n<li>\u5728JSF\u9875\u9762\u4e2d\u5982\u4f55\u6e32\u67d3\u4e0d\u540c\u7684\u7ec4\u4ef6\uff1f<\/li>\n<li>JSF\u652f\u6301\u591a\u4e2afaces\u914d\u7f6e\u6587\u4ef6\u5417\uff1f<\/li>\n<li>Backing Bean\u548cManaged Bean\u4e4b\u95f4\u6709\u54ea\u4e9b\u533a\u522b\uff1f<\/li>\n<li>\u5982\u4f55\u5728JSF\u4e2d\u663e\u793a\u9519\u8bef\u6d88\u606f\uff1f<\/li>\n<li>selectOne\u83dc\u5355\u6807\u7b7e\u5728JSF\u4e2d\u7684\u91cd\u8981\u6027\u662f\u4ec0\u4e48\uff1f<\/li>\n<li>\u89e3\u91caimmediate\u548crendered\u5c5e\u6027\uff1f<\/li>\n<li>JSF\u652f\u6301\u7684\u4e24\u79cd\u7ed1\u5b9a\u65b9\u5f0f\u6709\u54ea\u4e9b\uff1f<\/li>\n<li>JSF\u6846\u67b6\u6240\u9700\u7684\u914d\u7f6e\u6709\u54ea\u4e9b\uff1f<\/li>\n<li>\u4ec0\u4e48\u662fJSF\u5bfc\u822a\u89c4\u5219\uff1f<\/li>\n<li>JSF\u8f6c\u6362\u5668\u6807\u7b7e\u7684\u4f5c\u7528\u662f\u4ec0\u4e48\uff1f<\/li>\n<li>\u6570\u636e\u8868\u683c\u6807\u7b7e\u5728JSF\u4e2d\u7684\u597d\u5904\u6709\u54ea\u4e9b\uff1f<\/li>\n<li>\u5982\u4f55\u5728JSF\u4e2d\u5b9e\u73b0\u56fd\u9645\u5316\uff08i18n\uff09\uff1f<\/li>\n<li>\u7ec4\u4ef6\u6e32\u67d3\u6a21\u578b\u662f\u4ec0\u4e48\uff1f<\/li>\n<li>\u4ec0\u4e48\u662f\u6e32\u67d3\u5de5\u5177\u5305\uff1f<\/li>\n<li>\u4ec0\u4e48\u662f\u89c6\u56fe\u5bf9\u8c61\uff1f<\/li>\n<li>\u4ec0\u4e48\u662fBean\u8303\u56f4\uff1f<\/li>\n<li>JSF-1\u548cJSF-2\u4e4b\u95f4\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/li>\n<li>\u53ef\u4ee5\u6ca1\u6709faces-config.xml\u7684JSF\u5e94\u7528\u7a0b\u5e8f\u5417\uff1f<\/li>\n<li>JSF\u5e94\u7528\u7a0b\u5e8f\u7684\u4e00\u4e9b\u6700\u4f73\u5b9e\u8df5\u6709\u54ea\u4e9b\uff1f<\/li>\n<li>\u5982\u4f55\u5c06JSF\u4e0eSpring\u6846\u67b6\u8fdb\u884c\u6bd4\u8f83\uff1f<\/li>\n<li>\u4e3a\u4ec0\u4e48JSF\u4e0d\u5982Spring MVC\u7b49MVC\u6846\u67b6\u90a3\u4e48\u53d7\u6b22\u8fce\uff0c\u5c3d\u7ba1\u5b83\u66f4\u65e9\uff1f<\/li>\n<li>\u6211\u4eec\u53ef\u4ee5\u5c06JSF\u4e0e\u5176\u4ed6\u6d41\u884c\u7684\u6846\u67b6\uff08\u5982Spring\u3001Hibernate\u7b49\uff09\u96c6\u6210\u5417\uff1f<\/li>\n<\/ol>\n<h3>JSF \u9762\u8bd5\u95ee\u9898\u4e0e\u7b54\u6848<\/h3>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u4ec0\u4e48\u662fJSF\uff1f<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>Java Server Faces\uff08JSF\uff09\u6280\u672f\u662f\u4e00\u4e2a\u524d\u7aef\u6846\u67b6\uff0c\u901a\u8fc7\u91cd\u7528UI\u7ec4\u4ef6\u4f7f\u7528\u6237\u754c\u9762\u7ec4\u4ef6\u7684\u521b\u5efa\u66f4\u52a0\u7b80\u5355\u3002JSF\u57fa\u4e8e\u6a21\u578b\u89c6\u56fe\u63a7\u5236\u5668\u6a21\u5f0f\uff08MVC\uff09\u8bbe\u8ba1\uff0c\u5c06\u6f14\u793a\u3001\u63a7\u5236\u5668\u548c\u4e1a\u52a1\u903b\u8f91\u5206\u79bb\u3002\u8981\u5f00\u59cb\u4f7f\u7528JSF\uff0c\u8bf7\u9605\u8bfbJSF\u521d\u5b66\u8005\u6559\u7a0b\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>\u4ec0\u4e48\u662f\u6258\u7ba1Bean\uff1f<br \/>\n\u6258\u7ba1Bean\u662f\u4e00\u79cd\u5728JSF\u4e2d\u6ce8\u518c\u7684java\u7c7b\uff0c\u5b83\u4f7fUI\u548c\u4e1a\u52a1\u903b\u8f91\u4e4b\u95f4\u7684\u4ea4\u4e92\u6210\u4e3a\u53ef\u80fd\u3002\u53ef\u4ee5\u4f7f\u7528@ManagedBean\u6ce8\u89e3\u521b\u5efa\u6258\u7ba1Bean\u3002\u6709\u5173\u8be6\u7ec6\u793a\u4f8b\uff0c\u8bf7\u9605\u8bfbJSF\u6258\u7ba1Bean\u793a\u4f8b\u3002<\/p>\n<p>JSF\u63d0\u4f9b\u4e86\u54ea\u4e09\u79cd\u7c7b\u578b\u7684\u6587\u672c\u5b57\u6bb5\u6807\u7b7e\uff1f<br \/>\n\u4e09\u79cd\u7c7b\u578b\u7684\u6587\u672c\u5b57\u6bb5\u6807\u7b7e\u662f\uff1a<\/p>\n<p>&#8211; \u8fd9\u5c06\u5728\u6807\u7b7e\u5b57\u6bb5\u65c1\u8fb9\u6dfb\u52a0\u6587\u672c\u6846\u3002<br \/>\n&#8211; \u6b64\u7c7b\u578b\u7528\u4e8e\u5bc6\u7801\u5b57\u6bb5\uff0c\u8f93\u5165\u7684\u6570\u636e\u5c06\u88ab\u9690\u85cf\u3002<br \/>\n&#8211; \u5728\u8f93\u5165\u5927\u91cf\u5b57\u7b26\u65f6\u4f7f\u7528\u6b64\u7c7b\u578b\u5b57\u6bb5\u3002<\/p>\n<p>\u6709\u5173\u5b8c\u6574\u793a\u4f8b\uff0c\u8bf7\u53c2\u9605JSF\u6587\u672c\u7ec4\u4ef6\u3002<\/p>\n<p>@ManagedProperty\u6ce8\u89e3\u7684\u91cd\u8981\u6027\u662f\u4ec0\u4e48\uff1f<br \/>\n@ManagedProperty\u6ce8\u89e3\u4f7f\u6211\u4eec\u80fd\u591f\u5c06\u4e00\u4e2a\u6258\u7ba1Bean\u6ce8\u5165\u5230\u53e6\u4e00\u4e2a\u6258\u7ba1Bean\u4e2d\u3002\u8981\u4e86\u89e3\u5176\u5de5\u4f5c\u539f\u7406\uff0c\u8bf7\u9605\u8bfbJSF\u6ce8\u5165\u6258\u7ba1Bean\u3002<\/p>\n<p>@ApplicationScoped\u6ce8\u89e3\u8868\u793a\u4ec0\u4e48\uff1f<\/p>\n<pre class=\"post-pre\"><code>The `@ApplicationScoped` annotation indicates that the bean is valid as long as the web application is valid.\r\n<\/code><\/pre>\n<ol>\u5728JSF\u4e2d\uff0c\u8d44\u6e90\u6346\u7ed1\u662f\u6307\u5c06\u76f8\u5173\u7684\u8d44\u6e90\u6587\u4ef6\uff08\u4f8b\u5982\u6837\u5f0f\u8868\u3001\u811a\u672c\u6587\u4ef6\u7b49\uff09\u7ec4\u5408\u5728\u4e00\u8d77\uff0c\u4ee5\u63d0\u9ad8Web\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/ol>\n<pre class=\"post-pre\"><code>The phenomenon of storing the UI labels, date, status messages and other UI textual elements in a separate properties file instead of hardcoding these in a page is called resource bundling. We can use `h:outputLabel` element to pick these values from resource bundle properties file in JSF view pages, for a complete example please refer [JSF Resource Bundle Example](\/community\/tutorials\/jsf-resource-bundle-custom-messages-example-tutorial).\r\n<\/code><\/pre>\n<ol>\u8bf7\u89e3\u91ca\u6807\u7b7e\u7684required\u548crequiredMessage\u5c5e\u6027\uff1f<\/ol>\n<pre class=\"post-pre\"><code>Required attribute indicates that the field is mandatory when set to true. The requiredMessage attribute allows users to specify their own message for the ui components when the fields are mandatory. They are used for declarative validations in JSF view pages, for a complete example please read [JSF Declarative Validation](\/community\/tutorials\/jsf-validation-example-tutorial-validator-tag-custom-validator).\r\n<\/code><\/pre>\n<ol>JSF\u652f\u6301\u54ea\u4e9b\u4e0d\u540c\u7c7b\u578b\u7684\u9875\u9762\u5bfc\u822a\u65b9\u5f0f\uff1f<\/ol>\n<pre class=\"post-pre\"><code>The types of Page navigation supported in JSF are\r\n\r\n1.  Implicit Navigation\r\n2.  Navigation through Managed Bean\r\n3.  Navigation through faces-config.xml\r\n4.  Forward versus Redirect navigation\r\n5.  Conditional Navigation\r\n\r\nFor detailed explanation, please go through [JSF Navigation Rules](\/community\/tutorials\/jsf-navigation-rule-example-tutorial) and [JSF Action Method Navigation Rule Example](\/community\/tutorials\/jsf-action-method-navigation-example-tutorial-from-action-tag).\r\n<\/code><\/pre>\n<ol>JSF\u751f\u547d\u5468\u671f\u7684\u9636\u6bb5\u6709\u54ea\u4e9b\uff1f<\/ol>\n<pre class=\"post-pre\"><code>There are six lifecycle phases namely;\r\n\r\n1.  Restore view phase\r\n2.  Apply request values phase\r\n3.  Process validations phase\r\n4.  Update model values phase\r\n5.  Invoke application phase\r\n6.  Render response phase\r\n\r\nFor better understanding and detailed explanation of each of life cycle phase, please read [JSF Page Lifycycle Management](\/community\/tutorials\/jsf-page-lifecycle-management).\r\n<\/code><\/pre>\n<ol>\u6807\u7b7e\u7684\u4e00\u4e9b\u7279\u6027\u662f\u4ec0\u4e48\uff1f<\/ol>\n<pre class=\"post-pre\"><code>Some of the important h:form tag attributes are;\r\n\r\n-   id: This is the unique identifier used to identify a component.\r\n-   title: A title for an element of the form used as tooltip.\r\n-   onclick: invokes the javascript function to be called when a button is clicked next to an element.\r\n-   onsubmit: invokes javascript function to be called on click of form by a submit button.\r\n-   onreset: Javascript to be invoked on the reset of the elements in a form.\r\n-   ondblclick: Javascript code to be executed when the mouse is double clicked over a field in a form.\r\n-   onmouseup: Javascript code to be executed when the mouse button is released over a component.\r\n-   onmousedown: Javascript code to be executed when the mouse pointer is clicked down over this element.\r\n-   binding: value of the expression linked to a property in a backing bean.\r\n-   target: Name of the frame where the resource retrieved is to be displayed.\r\n-   accept: the contents list that the form can handle.\r\n-   acceptCharSet: defines the list of character encoding that the form will accept.\r\n-   style: The CSS style definitions that can be applied for the form\r\n-   prependId: flag that indicates whether id should be prepended to the form\r\n-   dir: Overrides default text functionality for this component.\r\n\r\nTo see form component in action, please go through [JSF Form Component Example](\/community\/tutorials\/jsf-form-components-example-tutorial).\r\n<\/code><\/pre>\n<ol>\u7528\u4e8e\u64cd\u4f5c\u548c\u5bfc\u822a\u7684\u547d\u4ee4\u7ec4\u4ef6\u6807\u7b7e\u6709\u54ea\u4e9b\uff1f<\/ol>\n<pre class=\"post-pre\"><code>The command component tags for performing action and navigation are\r\n\r\n1.  &lt;h:commandButton&gt; tag - The h:commandButton tag renders a button to submit a form thereby paving a way for processing the data entered by the user.\r\n2.  &lt;h:commandLink&gt; tag - The commandLink provides an hyperlink equivalent to anchor tag in HTML that acts like a submit button and can be associated with the backing beans or action class for event handling.\r\n\r\nFor detailed example, please go through [JSF Command Components Example](\/community\/tutorials\/jsf-command-component-tags-for-action-and-navigation).\r\n<\/code><\/pre>\n<ol>\u6570\u636e\u7ed1\u5b9a\u8868\u683c\u7ec4\u4ef6\u662f\u4ec0\u4e48\uff1f sh\u00ec ?)<\/ol>\n<pre class=\"post-pre\"><code>The components that are responsible for displaying the relational data in a tabular format are called data bound table components. The &lt;h:dataTable&gt; tag is used for displaying the data components. The &lt;h:column&gt; tag iterates over each record in the data source displayed in rows. Some of the attributes of the h:dataTable tag are;\r\n\r\n-   bgcolor: background color for the table that is displayed.\r\n-   border: width in pixel to be drawn around the table.\r\n-   cellpadding: Space between border of each cell and its contents.\r\n-   cellspacing: Space between left side of the table and leftmost column and also amount of space between the cells.\r\n-   columnClasses: List of css styles separated by comma to be applied to the columns of this table.\r\n-   bodyrows: List of row indices separated by comma to be applied for the \"tbody\" element should be started.\r\n\r\nTo see dataTable tag in action, please read [JSF dataTable tag](\/community\/tutorials\/jsf-datatable-example).\r\n<\/code><\/pre>\n<ol>\u4e00\u4e2a\u4e8b\u4ef6\u662f\u4ec0\u4e48\uff1f (Y\u012b g\u00e8 sh\u00ec ?)<\/ol>\n<pre class=\"post-pre\"><code>An event is defined as a signal triggered based upon the user actions such as click of button, hyperlink, changing the input value etc. JSF tells the component to invoke the appropriate listener class that process the event generated by the user.\r\n<\/code><\/pre>\n<ol>\u6211\u4eec\u5982\u4f55\u83b7\u5f97\u751f\u6210\u7684\u4e8b\u4ef6\uff1f<\/ol>\n<pre class=\"post-pre\"><code>The generated event can be obtained by calling event.getComponent as\r\n\r\n```\r\nUIComponent ui = new UIComponent();\r\nMyFacesEvent ev1 = new MyFacesEvent(ui);\r\nUIComponent sc1 = ev1.getComponent();\r\n```\r\n<\/code><\/pre>\n<ol>JSF \u4e8b\u4ef6\u6709\u54ea\u4e9b\u4e0d\u540c\u7c7b\u578b\uff1f<\/ol>\n<pre class=\"post-pre\"><code>There are three types of JSF events namely\r\n\r\n1.  Action Events: Action events are the events that are generated for the ui components like command button or command hyperlink.\r\n2.  Value Change Events: Value change events refers to the UI components textfield, radio button, list box etc. The value change event will get fired as soon as the value is changed in the UI component.\r\n3.  Phase Events: This type of event involves the events to be fired in one of the six phases of JSF lifecycle either during start or towards the end of each phase.\r\n\r\nYou can get more details about these events at [JSF Events Example](\/community\/tutorials\/jsf-event-listener-action-phase-value-change).\r\n<\/code><\/pre>\n<ol>\u4ec0\u4e48\u662f\u76d1\u542c\u5668\u7c7b\uff1f<\/ol>\n<pre class=\"post-pre\"><code>A class which is associated with an event is called a listener class. For example, if the event is a valueChange event then the corresponding listener class `ValueChangeListener` is associated with it. Read more at [JSF Listeners Example](\/community\/tutorials\/jsf-event-listener-action-phase-value-change) to learn more about these listeners.\r\n<\/code><\/pre>\n<ol>\u9762\u5177\u6807\u7b7e\u7684\u610f\u4e49\u662f\u4ec0\u4e48\uff1f<\/ol>\n<pre class=\"post-pre\"><code>JSF provides a special set of tags that gives the flexibility to manage common tags\/parts in one place for more than one application. These tags allow us to create a common layout that can be used across applications. You can include facelets tags using below code;\r\n\r\n```\r\n&lt;html\r\n   xmlns=\"https:\/\/www.w3.org\/1999\/xhtml\"\r\n   xmlns:ui=\"https:\/\/java.sun.com\/jsf\/facelets\"\r\n&gt;\r\n```\r\n\r\nI have written a very long article for facelets tags, go check it out at [JSF Facelets Tags Example](\/community\/tutorials\/jsf-facelet-tags-example-tutorial).\r\n<\/code><\/pre>\n<ol>\u4e00\u4e9b\u9762\u677f\u6807\u7b7e\u6709\u54ea\u4e9b\uff1f<\/ol>\n<pre class=\"post-pre\"><code>Some of the important facelets tags are;\r\n-   &lt;ui:component&gt; tag\r\n-   &lt;ui:composition&gt; tag\r\n-   &lt;ui:decorate&gt; tag\r\n-   &lt;ui:define&gt; tag\r\n-   &lt;ui:fragment&gt; tag\r\n-   &lt;ui:include&gt; tag\r\n<\/code><\/pre>\n<ol>JSF\u6709\u54ea\u4e9b\u4e0d\u540c\u7c7b\u578b\u7684\u9a8c\u8bc1\uff1f<\/ol>\n<pre class=\"post-pre\"><code>There are two types of validations namely;\r\n\r\n1.  **Declarative Validations**: The validations that are fired using JSF standard validators or Bean validators fall under declarative type.\r\n2.  **Imperative validation**: The standard validation messages would not be sufficient in all the cases and sometimes may require complex validations that are declared by the user overriding the standard validations and these are called Imperative validations.\r\n\r\nCheck out complete details of these validation types at [JSF Validation Example](\/community\/tutorials\/jsf-validation-example-tutorial-validator-tag-custom-validator).\r\n<\/code><\/pre>\n<ol>JSF EL\u652f\u6301\u54ea\u4e9b\u4e0d\u540c\u7c7b\u578b\u7684\u8868\u8fbe\u5f0f\uff1f<\/ol>\n<pre class=\"post-pre\"><code>JSF Expression Language supports following types of expressions.\r\n\r\n1.  Immediate value expressions\r\n2.  Deferred value expressions\r\n3.  Value expression and method expression\r\n\r\nCheck out complete details about these at [JSF EL Tutorial](\/community\/tutorials\/jsf-expression-language-jsf-el).\r\n<\/code><\/pre>\n<ol>\u4ec0\u4e48\u662f\u5373\u523b\u503c\u548c\u5ef6\u8fdf\u503c\u8868\u8fbe\u5f0f\uff1f sh\u00ec zh\u00ed h\u00e9 zh\u00ed sh\u00ec?)<\/ol>\n<pre class=\"post-pre\"><code>Immediate expressions are evaluated and results are rendered as soon as the page is displayed initially. The syntax for immediate evaluation is `${}`. Deferred expressions are evaluated during the lifecycle phase whenever it is requested by the user. The syntax for deferred evaluation is `#{expression}`.\r\n<\/code><\/pre>\n<ol>\u89e3\u91ca\u4ef7\u503c\u8868\u8fbe\u548c\u65b9\u6cd5\u8868\u8fbe\uff1f<\/ol>\n<pre class=\"post-pre\"><code>Value expressions usually fetch a value or set a value. These expressions can be further categorized into rvalue and lvalue expressions. lvalue expressions can both read and write data whereas rvalue expressions can only read data. A method expression allows user to invoke a public method of the bean that returns the result necessary for validating the data component and handling events.\r\n<\/code><\/pre>\n<ol>\u89e3\u91ca @ViewScoped\uff0c@SessionScoped\uff0c@CustomScoped\u548c@RequestScoped\u6ce8\u89e3\u7684\u4f5c\u7528\u662f\u4ec0\u4e48\uff1f<\/ol>\n<pre class=\"post-pre\"><code>**@ViewScoped**: annotation indicates that the bean is alive as long as the user interacts with the same JSF view page in the browser. **@SessionScoped**: annotation indicates that the bean is valid as long as the HTTP session is alive. **@CustomScoped**: annotation indicates that the bean lives as long as the bean's entry in the custom Map which is created for this scope lives. **@RequestScoped**: annotation indicates that the Bean lives as long as the HTTP request-response lives.\r\n<\/code><\/pre>\n<ol>\u89e3\u91ca\u5728JSF\u4e2d\u58f0\u660e\u6258\u7ba1Bean\u7684\u4e0d\u540c\u65b9\u5f0f\u3002<\/ol>\n<pre class=\"post-pre\"><code>1.  Use `@ManagedBean` annotation in the java class indicating that the class is a managed bean as;\r\n    \r\n    ```\r\n    @ManagedBean(name=\"Greetings\", eager=\"true\")\r\n    ```\r\n    \r\n    If the name attribute is not specified the name is defaulted to the class name as java naming standards. For example class Car will be named \"car\" and CarDetails will be named \"carDetails\".\r\n2.  Declare the managed bean in faces-config.xml file as;\r\n    \r\n    ```\r\n    &lt;managed-bean&gt;\r\n      \t&lt;managed-bean-name&gt;Greetings&lt;\/managed-bean-name&gt;\r\n      \t&lt;managed-bean-class&gt;com.Greetings.Greetings&lt;\/managed-bean-class&gt;\r\n     \t&lt;managed-bean-scope&gt;request&lt;\/managed-bean-scope&gt;\r\n    &lt;\/managed-bean&gt;\r\n    ```\r\n<\/code><\/pre>\n<ol>\u6258\u7ba1Bean\u4e2d\u7684\u540d\u79f0\u548c\u6e34\u671b\u5c5e\u6027\u6709\u4ec0\u4e48\u91cd\u8981\u610f\u4e49\uff1f<\/ol>\n<pre class=\"post-pre\"><code>**name**: The name attribute indicates the managed bean with the name specified. If the name is not specified then the bean name is same as the class name. **eager**: If eager is set to \"true\" then managed bean is created before it is requested for the first time and if set to false the bean is created when it is requested.\r\n<\/code><\/pre>\n<ol>\u5217\u4e3e\u4e00\u4e9b\u5728JSF\u4e2d\u5e38\u7528\u7684\u9a8c\u8bc1\u6807\u7b7e\u3002<\/ol>\n<pre class=\"post-pre\"><code>-   f:validateLength: Validates length of a string\r\n-   f:validateLongRange: Validates range of numeric value\r\n-   f:validateDoubleRange: Validates range of float value\r\n-   f:validateRegex: Validate JSF component with a given regular expression\r\n<\/code><\/pre>\n<ol>\u4f7f\u7528JSF\u6846\u67b6\u7684\u597d\u5904\u6709\u54ea\u4e9b\uff1f<\/ol>\n<pre class=\"post-pre\"><code>Some of the benefits of using JSF framework are;\r\n-   Clean separation between presentation and business logic.\r\n-   Manages UI state across multiple server requests.\r\n-   Implementation of custom components.\r\n-   Easier flow of data between the components.\r\n-   JSF specs that helps custom implementations such as PrimeFaces\r\n<\/code><\/pre>\n<ol>\u6709\u54ea\u4e9b\u4e0d\u540c\u7684JSF\u8f6c\u6362\u5668\u6807\u7b7e\uff1f<\/ol>\n<pre class=\"post-pre\"><code>-   f:convertNumber: tag is used to convert a string value to a number of required format.\r\n-   f:convertDateTime: tag is used to convert a string value to a date of required format.\r\n-   CustomConverter: allows user to define their own convertor in JSF.\r\n<\/code><\/pre>\n<ol>\u5217\u4e3e\u8868\u8fbe\u8bed\u8a00\u7684\u597d\u5904\u6709\u54ea\u4e9b\uff1f<\/ol>\n<pre class=\"post-pre\"><code>-   Arithmetic, logical, relational operations can be used in expression language.\r\n-   Automatic type conversion.\r\n-   Shows missing values as empty strings instead of NullPointerException.\r\n-   Provides easy access to predefined objects such as request.\r\n<\/code><\/pre>\n<ol>\u4e00\u4e2a\u5907\u7528\u8c46\u662f\u4ec0\u4e48\uff1f<\/ol>\n<pre class=\"post-pre\"><code>A JavaServer Faces application includes one or more backing beans, each of which is a type of managed bean that can be associated with the components used in a particular page.\r\n<\/code><\/pre>\n<ol>JSF \u6807\u51c6\u6807\u7b7e\u5e93\u662f\u4ec0\u4e48\uff1f<\/ol>\n<pre class=\"post-pre\"><code>1.  JSF Core Tags library\r\n2.  JSF HTML tags library\r\n\r\nUse below namespace configurations to use them in JSF xhtml pages.\r\n\r\n```\r\n&lt;html xmlns=\"https:\/\/www.w3.org\/1999\/xhtml\"\r\n    xmlns:h=\"https:\/\/java.sun.com\/jsf\/html\"\r\n    xmlns:ui=\"https:\/\/java.sun.com\/jsf\/facelets\"\r\n    xmlns:c=\"https:\/\/java.sun.com\/jsf\/core\"&gt;\r\n```\r\n\r\nThe html tags can now be used as with the h prefix as &lt;h:head&gt;,&lt;h:form&gt; etc and core tags with c prefix as &lt;c:validateBean&gt;,&lt;c:validator&gt; etc.\r\n<\/code><\/pre>\n<ol>\u5907\u7528bean\u65b9\u6cd5\u6267\u884c\u7684\u4e00\u4e9b\u529f\u80fd\u662f\u4ec0\u4e48\uff1f<\/ol>\n<pre class=\"post-pre\"><code>-   Validating a component\u2019s data\r\n-   Handling an event fired by a component\r\n-   Performs processing to determine the next page to which the application must navigate\r\n<\/code><\/pre>\n<ol>JSF API\u6709\u54ea\u4e9b\u4e0d\u540c\u7684\u5b9e\u73b0\u65b9\u5f0f\uff1f<\/ol>\n<pre class=\"post-pre\"><code>-   ADF Faces: Oracle's implementation for the JSF standard.\r\n-   Reference Implementation (RI): by Sun Microsystems.\r\n-   Apache MyFaces: open source JavaServer Faces (JSF) implementation.\r\n-   Primefaces: JSF components with Ajax framework.\r\n<\/code><\/pre>\n<ol>\u89e3\u91caJSF\u67b6\u6784\u662f\u4ec0\u4e48\uff1f<\/ol>\n<pre class=\"post-pre\"><code>JSF is developed based on the Model View Controller(MVC) pattern. The Model VIew Controller separates the business logic from presentation. The JSF application contains\r\n\r\n-   UI components represented as stateful objects on the server\r\n-   Server-side helper classes\r\n-   Validators, event handlers, and navigation handlers\r\n-   Application configuration resource file for configuring application resources\r\n-   JavaBeans components as models containing application-specific functionality and data\r\n-   A custom tag library for representing event handlers and validators\r\n-   A custom tag library for rendering UI components\r\n\r\nBelow image shows the JSF applications architecture diagram. [![JSF Architecture Diagram, JSF Interview Questions, JSF Interview Questions and Answers for experienced](https:\/\/scdev.nyc3.cdn.digitaloceanspaces.com\/2015\/03\/JSF-Architecture-Diagram-450x288.png)](https:\/\/scdev.nyc3.cdn.digitaloceanspaces.com\/2015\/03\/JSF-Architecture-Diagram.png)\r\n<\/code><\/pre>\n<ol>\u5728JSF\u9875\u9762\u4e2d\uff0c\u4e0d\u540c\u7ec4\u4ef6\u662f\u5982\u4f55\u5448\u73b0\u7684\uff1f<\/ol>\n<pre class=\"post-pre\"><code>JSF components are rendered in the xhtml pages by the tag libraries included, such as JSF core, html and facelets tag libraries.\r\n<\/code><\/pre>\n<ol>JSF\u80fd\u591f\u652f\u6301\u591a\u4e2a\u9762\u5411\u914d\u7f6e\u6587\u4ef6\u5417\uff1f<\/ol>\n<pre class=\"post-pre\"><code>Yes, any number of faces configuration files can be used but should be declared in the web.xml file as shown below.\r\n\r\n```\r\n&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;web-app version=\"3.1\" xmlns=\"https:\/\/xmlns.jcp.org\/xml\/ns\/javaee\" \r\n\txmlns:xsi=\"https:\/\/www.w3.org\/2001\/XMLSchema-instance\" \r\n\txsi:schemaLocation=\"https:\/\/xmlns.jcp.org\/xml\/ns\/javaee \r\n\thttps:\/\/xmlns.jcp.org\/xml\/ns\/javaee\/web-app_3_1.xsd\"&gt;\r\n&lt;context-param&gt;\r\n\t&lt;param-name&gt;javax.faces.CONFIG_FILES&lt;\/param-name&gt;\r\n\t&lt;param-value&gt;\/WEB-INF\/faces-config1.xml,\/WEB-INF\/faces-config2.xml&lt;\/param-value&gt;\r\n&lt;\/context-param&gt;\r\n&lt;\/web-app&gt;\r\n```\r\n<\/code><\/pre>\n<ol>Backing Bean\u548cManaged Bean\u4e4b\u95f4\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/ol>\n<pre class=\"post-pre\"><code>Backing Beans should be defined in request scope whereas managed bean can be defined in request,session or application scopes.Backing bean is referenced by a form whereas a managed bean is registered with JSF and created automatically when needed.\r\n<\/code><\/pre>\n<ol>\u5982\u4f55\u5728JSF\u4e2d\u663e\u793a\u9519\u8bef\u4fe1\u606f\uff1f<\/ol>\n<pre class=\"post-pre\"><code>The h:messages tag shows all the error messages at one place corresponding to UI elements. The \"for\" attribute can be used to represent the field for which error message has to be displayed. For a complete example, please read [JSF Error Messages Example](\/community\/tutorials\/jsf-error-messages-example-tutorial).\r\n<\/code><\/pre>\n<ol>JSF\u4e2d\u7684selectOne\u83dc\u5355\u6807\u7b7e\u6709\u4f55\u610f\u4e49\uff1f<\/ol>\n<pre class=\"post-pre\"><code>The selectOne enables users to select a single value from the list of values. This component can be rendered as a list box, a set of radio buttons or a menu.\r\n<\/code><\/pre>\n<ol>\u89e3\u91ca\u5373\u65f6\u5c5e\u6027\u548c\u6e32\u67d3\u5c5e\u6027\u662f\u4ec0\u4e48\u610f\u601d\uff1f<\/ol>\n<pre class=\"post-pre\"><code>The immediate attribute if set to true can force validations, events and conversions processed during request phase of the lifecycle. Command component\u2019s immediate attribute indicates what happens when the component gets activated. If the button\u2019s immediate attribute is set to true and associated text field\u2019s immediate attribute set to false then the event is processed without applying the field\u2019s value to the model. In other words the value entered in the field does not even reach the model when the button is clicked but immediately processed in the above scenario. The rendered attribute indicates whether a component should be rendered or not in the view page. Rendered attribute can use arithmetic operators and literals with rvalue expression but not lvalue expressions.\r\n<\/code><\/pre>\n<ol>JSF\u652f\u6301\u54ea\u4e24\u79cd\u7ed1\u5b9a\u65b9\u5f0f\uff1f<\/ol>\n<pre class=\"post-pre\"><code>1.  Binding the component\u2019s value to a bean property or other external data source\r\n2.  Binding the component\u2019s instance to a bean property\r\n<\/code><\/pre>\n<ol>JSF\u6846\u67b6\u9700\u8981\u54ea\u4e9b\u5fc5\u8981\u7684\u914d\u7f6e?<\/ol>\n<pre class=\"post-pre\"><code>There are two configuration files namely;\r\n1.  web.xml: This is the general web application configuration file containing the details of deployment. This contains the faces config file responsible for handling the application.\r\n2.  faces-config.xml: allows to configure the application, managed beans, converters, validators, and navigation.\r\n<\/code><\/pre>\n<ol>JSF\u5bfc\u822a\u89c4\u5219\u662f\u4ec0\u4e48\uff1f<\/ol>\n<pre class=\"post-pre\"><code>The rules provided by JSF Framework to describe the view to be shown when a button or link is clicked is called a navigation rule. For complete details, please read [JSF Navigation Rules Tutorial](\/community\/tutorials\/jsf-navigation-rule-example-tutorial).\r\n<\/code><\/pre>\n<ol>JSF\u8f6c\u6362\u5668\u6807\u7b7e\u7684\u4f5c\u7528\u662f\u4ec0\u4e48\uff1f<\/ol>\n<pre class=\"post-pre\"><code>The convertor tags convert the UI component's data to object used in a managed bean and vice versa. For example, these tags can convert a text into date object and can validate the format of input as well.\r\n<\/code><\/pre>\n<ol>JSF\u4e2d\u6570\u636e\u8868\u6807\u7b7e\u7684\u597d\u5904\u6709\u54ea\u4e9b\uff1f<\/ol>\n<pre class=\"post-pre\"><code>-   DataTable can iterate over collection or array of values to display data.\r\n-   DataTable provides attributes to modify its data in easy way\r\n\r\nRead more at [JSF Data Table Example](\/community\/tutorials\/jsf-datatable-example).\r\n<\/code><\/pre>\n<ol>\u5982\u4f55\u5728JSF\u4e2d\u5b9e\u73b0\u56fd\u9645\u5316\uff08i18n\uff09\uff1f<\/ol>\n<pre class=\"post-pre\"><code>Internationalization is a mechanism in which status messages, GUI component labels, currency, date are stored outside the source code in resource bundles and retrieved dynamically rather than hardcoding in the program based on the user locale.\r\n<\/code><\/pre>\n<ol>\u7ec4\u4ef6\u6e32\u67d3\u6a21\u578b\u662f\u4ec0\u4e48\uff1f sh\u00ec ?)<\/ol>\n<pre class=\"post-pre\"><code>The JavaServer Faces component architecture is designed such that the functionality of the components is defined by the component classes, whereas the actualities of the rendering itself can be defined by a separate renderer called as component rendering model.\r\n<\/code><\/pre>\n<ol>\u4ec0\u4e48\u662f\u6e32\u67d3\u5de5\u5177\u5305\uff1f<\/ol>\n<pre class=\"post-pre\"><code>A render kit defines how component classes map to component tags that are appropriate for a particular client.\r\n<\/code><\/pre>\n<ol>\u89c6\u56fe\u5bf9\u8c61\u662f\u4ec0\u4e48\uff1f<\/ol>\n<pre class=\"post-pre\"><code>A view object is a model object used specifically in the presentation tier but defined outside it. It contains the data that must be displayed in the view layer and the logic to validate user input, handle events, and interact with the business-logic tier.\r\n<\/code><\/pre>\n<ol>\u4f60\u5bf9&#8221;Bean\u8303\u56f4&#8221;\u662f\u4ec0\u4e48\u610f\u601d\uff1f<\/ol>\n<pre class=\"post-pre\"><code>Bean scope is the mechanism of binding the beans and other objects to be available in the different components of a web application.\r\n<\/code><\/pre>\n<ol>JSF-1 \u548c JSF-2 \u4e4b\u95f4\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/ol>\n<pre class=\"post-pre\"><code>-   JSF1 does not support the usage of annotations but JSF2 supports annotations that makes it far better than JSF1.\r\n-   JSF1 Ajax support was limited, however JSF2 support all the ajax features.\r\n-   JSF1 does not provide Template concepts whereas JSF2 does.\r\n-   JSF1 was first released and API was having a lot of bugs, JSF2 is totally redesigned and can be used as MVC framework in larger applications.\r\n<\/code><\/pre>\n<ol>\u6211\u4eec\u53ef\u4ee5\u5728\u6ca1\u6709faces-config.xml\u7684\u60c5\u51b5\u4e0b\u4f7f\u7528JSF\u5e94\u7528\u7a0b\u5e8f\u5417\uff1f<\/ol>\n<pre class=\"post-pre\"><code>In JSF 1.0 faces-config.xml is mandatory whereas JSF 2.0 supports annotations which does not need faces-config.xml.\r\n<\/code><\/pre>\n<ol>JSF\u5e94\u7528\u7684\u4e00\u4e9b\u6700\u4f73\u5b9e\u8df5\u662f\u4ec0\u4e48\uff1f<\/ol>\n<pre class=\"post-pre\"><code>The best practices for JSF application includes\r\n-   Avoid using JSF components for static value.\r\n-   Short component Id\r\n-   Avoid component bindings\r\n-   Facelets for dynamic includes\r\n<\/code><\/pre>\n<ol>\u4f60\u5982\u4f55\u5c06JSF\u4e0eSpring\u6846\u67b6\u8fdb\u884c\u6bd4\u8f83\uff1f<\/ol>\n<pre class=\"post-pre\"><code>Spring uses Inversion of Control and Dependency Injection whereas JSF does not. Spring has built in modules for Login-Logout available for ready integration whereas in JSF we have to write the login feature manually. Since Spring uses dependency injection the user based pojo classes can be injected with springs whereas JSF is tightly coupled with Java EE architecture.\r\n<\/code><\/pre>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u4e3a\u4ec0\u4e48JSF\u4e0d\u50cfSpring MVC\u90a3\u6837\u53d7\u6b22\u8fce\uff0c\u5c3d\u7ba1JSF\u6bd4\u5b83\u66f4\u65e9\u63a8\u51fa\uff1f<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u4e3a\u4ec0\u4e48JSF\u4e0d\u50cfSpring MVC\u90a3\u6837\u53d7\u6b22\u8fce\uff0c\u5c3d\u7ba1JSF\u53d1\u5e03\u65f6\u95f4\u66f4\u65e9\uff1f<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\u4e3a\u4ec0\u4e48JSF\u76f8\u6bd4Spring MVC\u4e0d\u90a3\u4e48\u53d7\u6b22\u8fce\uff0c\u5c3d\u7ba1\u5b83\u66f4\u8001\uff1f<\/ol>\n<pre class=\"post-pre\"><code>Some of the reasons I could thought of are;\r\n-   There are many implementations of JSF like Mojarra, Primefaces, Richfaces etc which makes it difficult for the user to comprehend learn and adapt to whereas Spring MVC has only one implementation maintained by a Single group of developers which avoids confusion.\r\n-   Spring has got great integration with data management through standalone or ORM frameworks out of the box which is lacking in JSF based implementation.\r\n-   DI and IOC design patterns makes it very easy to integrate existing legacy applications with new Spring based applications whereas JSF does not have such kind of capabilities.\r\n-   JSF is a component based framework whereas Spring is a Request-Response based framework and hence easy to understand and relates closely to MVC, Struts2 and other similar frameworks\r\n<\/code><\/pre>\n<ol>\u6211\u4eec\u80fd\u5c06JSF\u4e0e\u5176\u4ed6\u6d41\u884c\u7684\u6846\u67b6\u5982Spring\u3001Hibernate\u7b49\u96c6\u6210\u5417\uff1f<\/ol>\n<pre class=\"post-pre\"><code>Yes, we can integrate JSF framework with Spring, Hibernate, JDBC etc. Since JSF is more focused on view components, we can utilize it for user interface and other frameworks as backend server side integration and ORM tools. Some of the posts you should look for integrations are;\r\n-   [JSF and JDBC integration example](\/community\/tutorials\/jsf-database-example-mysql-jdbc)\r\n-   [JSF and Spring MVC integration example](\/community\/tutorials\/spring-jsf-integration)\r\n-   [JSF, Spring MVC and Hibernate integration example](\/community\/tutorials\/jsf-spring-hibernate-integration-example-tutorial)\r\n-   [JSF Authentication Login Logout example](\/community\/tutorials\/jsf-authentication-login-logout-database-example) showing use of HttpSession for session management\r\n<\/code><\/pre>\n<p>\u5173\u4e8eJSF\u7684\u9762\u8bd5\u95ee\u9898\u548c\u7b54\u6848\u5c31\u662f\u8fd9\u4e9b\u4e86\uff0c\u6211\u5e0c\u671b\u5b83\u4eec\u80fd\u5e2e\u52a9\u4f60\u5728JSF\u76f8\u5173\u95ee\u9898\u7684\u9762\u8bd5\u4e2d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u6211\u64b0\u5199\u4e86\u8bb8\u591a\u5173\u4e8eJSF\u6846\u67b6\u7684\u5185\u5bb9\uff0c\u56e0\u6b64\u73b0\u5728\u6b63\u662f\u6574\u7406\u4e00\u7bc7\u5173\u4e8eJSF\u9762\u8bd5\u95ee\u9898\u4e0e\u7b54\u6848\u6587\u7ae0\u7684\u597d\u65f6\u673a\u3002\u4ee5\u4e0b\u662f\u6211\u7cbe\u5fc3\u6536 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[1765,744,2039],"class_list":["post-751","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-javaserver-faces","tag-java","tag-jsf"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>2023\u6700\u65b0JSF(JavaServer Faces)\u9762\u8bd5\u9898\u4e0e\u7b54\u6848\u5927\u5168 - Java\u5f00\u53d1\u5fc5\u5907\u6307\u5357 - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"\u6574\u7406\u4e862023\u5e74\u6700\u65b0JSF(JavaServer Faces)\u9762\u8bd5\u95ee\u9898\u4e0e\u8be6\u7ec6\u7b54\u6848\uff0c\u6db5\u76d6\u57fa\u7840\u6982\u5ff5\u3001\u751f\u547d\u5468\u671f\u3001\u7ec4\u4ef6\u5e93\u3001\u5bfc\u822a\u89c4\u5219\u7b49\u6838\u5fc3\u77e5\u8bc6\u70b9\u3002\u5e2e\u52a9Java\u5f00\u53d1\u8005\u51c6\u5907\u6280\u672f\u9762\u8bd5\uff0c\u6df1\u5165\u7406\u89e3JSF\u6846\u67b6\u539f\u7406\u4e0e\u5e94\u7528\u3002\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/jsf-\u9762\u8bd5\u95ee\u9898\u4e0e\u56de\u7b54\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"2023\u6700\u65b0JSF(JavaServer Faces)\u9762\u8bd5\u9898\u4e0e\u7b54\u6848\u5927\u5168 - Java\u5f00\u53d1\u5fc5\u5907\u6307\u5357\" \/>\n<meta property=\"og:description\" content=\"\u6574\u7406\u4e862023\u5e74\u6700\u65b0JSF(JavaServer Faces)\u9762\u8bd5\u95ee\u9898\u4e0e\u8be6\u7ec6\u7b54\u6848\uff0c\u6db5\u76d6\u57fa\u7840\u6982\u5ff5\u3001\u751f\u547d\u5468\u671f\u3001\u7ec4\u4ef6\u5e93\u3001\u5bfc\u822a\u89c4\u5219\u7b49\u6838\u5fc3\u77e5\u8bc6\u70b9\u3002\u5e2e\u52a9Java\u5f00\u53d1\u8005\u51c6\u5907\u6280\u672f\u9762\u8bd5\uff0c\u6df1\u5165\u7406\u89e3JSF\u6846\u67b6\u539f\u7406\u4e0e\u5e94\u7528\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/jsf-\u9762\u8bd5\u95ee\u9898\u4e0e\u56de\u7b54\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-01-05T06:11:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-02T22:16:14+00:00\" \/>\n<meta name=\"author\" content=\"\u97f5, \u79d1\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u97f5, \u79d1\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/jsf-%e9%9d%a2%e8%af%95%e9%97%ae%e9%a2%98%e4%b8%8e%e5%9b%9e%e7%ad%94\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/jsf-%e9%9d%a2%e8%af%95%e9%97%ae%e9%a2%98%e4%b8%8e%e5%9b%9e%e7%ad%94\/\",\"name\":\"2023\u6700\u65b0JSF(JavaServer Faces)\u9762\u8bd5\u9898\u4e0e\u7b54\u6848\u5927\u5168 - Java\u5f00\u53d1\u5fc5\u5907\u6307\u5357 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-01-05T06:11:38+00:00\",\"dateModified\":\"2025-08-02T22:16:14+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/6530331a63adef3b3443a1fab53a0e6e\"},\"description\":\"\u6574\u7406\u4e862023\u5e74\u6700\u65b0JSF(JavaServer Faces)\u9762\u8bd5\u95ee\u9898\u4e0e\u8be6\u7ec6\u7b54\u6848\uff0c\u6db5\u76d6\u57fa\u7840\u6982\u5ff5\u3001\u751f\u547d\u5468\u671f\u3001\u7ec4\u4ef6\u5e93\u3001\u5bfc\u822a\u89c4\u5219\u7b49\u6838\u5fc3\u77e5\u8bc6\u70b9\u3002\u5e2e\u52a9Java\u5f00\u53d1\u8005\u51c6\u5907\u6280\u672f\u9762\u8bd5\uff0c\u6df1\u5165\u7406\u89e3JSF\u6846\u67b6\u539f\u7406\u4e0e\u5e94\u7528\u3002\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/jsf-%e9%9d%a2%e8%af%95%e9%97%ae%e9%a2%98%e4%b8%8e%e5%9b%9e%e7%ad%94\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/jsf-%e9%9d%a2%e8%af%95%e9%97%ae%e9%a2%98%e4%b8%8e%e5%9b%9e%e7%ad%94\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/jsf-%e9%9d%a2%e8%af%95%e9%97%ae%e9%a2%98%e4%b8%8e%e5%9b%9e%e7%ad%94\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"2023\u6700\u65b0JSF(JavaServer Faces)\u9762\u8bd5\u9898\u4e0e\u7b54\u6848\u5927\u5168 &#8211; Java\u5f00\u53d1\u5fc5\u5907\u6307\u5357\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/6530331a63adef3b3443a1fab53a0e6e\",\"name\":\"\u97f5, \u79d1\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g\",\"caption\":\"\u97f5, \u79d1\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/yunke\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/jsf-%e9%9d%a2%e8%af%95%e9%97%ae%e9%a2%98%e4%b8%8e%e5%9b%9e%e7%ad%94\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"2023\u6700\u65b0JSF(JavaServer Faces)\u9762\u8bd5\u9898\u4e0e\u7b54\u6848\u5927\u5168 - Java\u5f00\u53d1\u5fc5\u5907\u6307\u5357 - Blog - Silicon Cloud","description":"\u6574\u7406\u4e862023\u5e74\u6700\u65b0JSF(JavaServer Faces)\u9762\u8bd5\u95ee\u9898\u4e0e\u8be6\u7ec6\u7b54\u6848\uff0c\u6db5\u76d6\u57fa\u7840\u6982\u5ff5\u3001\u751f\u547d\u5468\u671f\u3001\u7ec4\u4ef6\u5e93\u3001\u5bfc\u822a\u89c4\u5219\u7b49\u6838\u5fc3\u77e5\u8bc6\u70b9\u3002\u5e2e\u52a9Java\u5f00\u53d1\u8005\u51c6\u5907\u6280\u672f\u9762\u8bd5\uff0c\u6df1\u5165\u7406\u89e3JSF\u6846\u67b6\u539f\u7406\u4e0e\u5e94\u7528\u3002","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/jsf-\u9762\u8bd5\u95ee\u9898\u4e0e\u56de\u7b54\/","og_locale":"zh_CN","og_type":"article","og_title":"2023\u6700\u65b0JSF(JavaServer Faces)\u9762\u8bd5\u9898\u4e0e\u7b54\u6848\u5927\u5168 - Java\u5f00\u53d1\u5fc5\u5907\u6307\u5357","og_description":"\u6574\u7406\u4e862023\u5e74\u6700\u65b0JSF(JavaServer Faces)\u9762\u8bd5\u95ee\u9898\u4e0e\u8be6\u7ec6\u7b54\u6848\uff0c\u6db5\u76d6\u57fa\u7840\u6982\u5ff5\u3001\u751f\u547d\u5468\u671f\u3001\u7ec4\u4ef6\u5e93\u3001\u5bfc\u822a\u89c4\u5219\u7b49\u6838\u5fc3\u77e5\u8bc6\u70b9\u3002\u5e2e\u52a9Java\u5f00\u53d1\u8005\u51c6\u5907\u6280\u672f\u9762\u8bd5\uff0c\u6df1\u5165\u7406\u89e3JSF\u6846\u67b6\u539f\u7406\u4e0e\u5e94\u7528\u3002","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/jsf-\u9762\u8bd5\u95ee\u9898\u4e0e\u56de\u7b54\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-01-05T06:11:38+00:00","article_modified_time":"2025-08-02T22:16:14+00:00","author":"\u97f5, \u79d1","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u97f5, \u79d1","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/jsf-%e9%9d%a2%e8%af%95%e9%97%ae%e9%a2%98%e4%b8%8e%e5%9b%9e%e7%ad%94\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/jsf-%e9%9d%a2%e8%af%95%e9%97%ae%e9%a2%98%e4%b8%8e%e5%9b%9e%e7%ad%94\/","name":"2023\u6700\u65b0JSF(JavaServer Faces)\u9762\u8bd5\u9898\u4e0e\u7b54\u6848\u5927\u5168 - Java\u5f00\u53d1\u5fc5\u5907\u6307\u5357 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-01-05T06:11:38+00:00","dateModified":"2025-08-02T22:16:14+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/6530331a63adef3b3443a1fab53a0e6e"},"description":"\u6574\u7406\u4e862023\u5e74\u6700\u65b0JSF(JavaServer Faces)\u9762\u8bd5\u95ee\u9898\u4e0e\u8be6\u7ec6\u7b54\u6848\uff0c\u6db5\u76d6\u57fa\u7840\u6982\u5ff5\u3001\u751f\u547d\u5468\u671f\u3001\u7ec4\u4ef6\u5e93\u3001\u5bfc\u822a\u89c4\u5219\u7b49\u6838\u5fc3\u77e5\u8bc6\u70b9\u3002\u5e2e\u52a9Java\u5f00\u53d1\u8005\u51c6\u5907\u6280\u672f\u9762\u8bd5\uff0c\u6df1\u5165\u7406\u89e3JSF\u6846\u67b6\u539f\u7406\u4e0e\u5e94\u7528\u3002","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/jsf-%e9%9d%a2%e8%af%95%e9%97%ae%e9%a2%98%e4%b8%8e%e5%9b%9e%e7%ad%94\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/jsf-%e9%9d%a2%e8%af%95%e9%97%ae%e9%a2%98%e4%b8%8e%e5%9b%9e%e7%ad%94\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/jsf-%e9%9d%a2%e8%af%95%e9%97%ae%e9%a2%98%e4%b8%8e%e5%9b%9e%e7%ad%94\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"2023\u6700\u65b0JSF(JavaServer Faces)\u9762\u8bd5\u9898\u4e0e\u7b54\u6848\u5927\u5168 &#8211; Java\u5f00\u53d1\u5fc5\u5907\u6307\u5357"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/6530331a63adef3b3443a1fab53a0e6e","name":"\u97f5, \u79d1","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g","caption":"\u97f5, \u79d1"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/yunke\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/jsf-%e9%9d%a2%e8%af%95%e9%97%ae%e9%a2%98%e4%b8%8e%e5%9b%9e%e7%ad%94\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/751","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=751"}],"version-history":[{"count":4,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/751\/revisions"}],"predecessor-version":[{"id":110619,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/751\/revisions\/110619"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=751"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=751"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=751"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}