日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

完整的WebApplication JSF EJB JPA JAAS –第2部分

發(fā)布時間:2023/12/3 javascript 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 完整的WebApplication JSF EJB JPA JAAS –第2部分 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
視圖–創(chuàng)建和JSF設置

本教程是第1部分的繼續(xù)。

讓我們創(chuàng)建一個新的Dynamic Web Project 。 如下圖所示創(chuàng)建它:

注意:在某些時候,Eclipse會詢問您是否要添加JSF功能(自動完成),然后啟用它。 就像下面的屏幕一樣:

創(chuàng)建項目后,讓我們編輯“ web.xml”文件; 它應該具有與以下相同的代碼:

<?xml version='1.0' encoding='UTF-8'?> <web-app xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'xmlns='http://java.sun.com/xml/ns/javaee' xmlns:web='http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd'xsi:schemaLocation='http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd'id='WebApp_ID' version='3.0'><display-name>CrudJSF</display-name><welcome-file-list><welcome-file>pages/protected/user/listAllDogs.xhtml</welcome-file></welcome-file-list><servlet><servlet-name>Faces Servlet</servlet-name><servlet-class>javax.faces.webapp.FacesServlet</servlet-class><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>Faces Servlet</servlet-name><url-pattern>/faces/*</url-pattern><url-pattern>*.jsf</url-pattern><url-pattern>*.xhtml</url-pattern></servlet-mapping><!-- Protected area definition --><security-constraint><web-resource-collection><web-resource-name>Restricted Area - ADMIN Only</web-resource-name><url-pattern>/pages/protected/admin/*</url-pattern></web-resource-collection><auth-constraint><role-name>ADMIN</role-name></auth-constraint></security-constraint><security-constraint><web-resource-collection><web-resource-name>Restricted Area - USER and ADMIN</web-resource-name><url-pattern>/pages/protected/user/*</url-pattern></web-resource-collection><auth-constraint><role-name>USER</role-name><role-name>ADMIN</role-name></auth-constraint></security-constraint><!-- Login page --><login-config><auth-method>FORM</auth-method><form-login-config><form-login-page>/pages/public/login.xhtml</form-login-page><form-error-page>/pages/public/loginError.xhtml</form-error-page></form-login-config></login-config><!-- System roles --><security-role><role-name>ADMIN</role-name></security-role><security-role><role-name>USER</role-name></security-role> </web-app>

您不必擔心是否會出現(xiàn)一些警告/錯誤。 我們稍后會解決。 請注意,我已經(jīng)添加了我們需要的所有JAAS代碼(如果您想獲得有關這些JAAS配置的詳細信息,可以在此處進行檢查: 使用JAAS和JSF的用戶登錄驗證 )。

根據(jù)JAAS的配置,普通用戶(USER角色)將只看到用戶文件夾中的文件,而這些文件僅僅是我們數(shù)據(jù)庫中記錄的狗的列表; ADMIN將能夠執(zhí)行所有CRUD操作,因為所有頁面都位于admins文件夾內(nèi)。

我們的“ faces-config.xml”應具有以下代碼:

<?xml version='1.0' encoding='UTF-8'?><faces-configxmlns='http://java.sun.com/xml/ns/javaee'xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'xsi:schemaLocation='http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd'version='2.0'><navigation-rule><navigation-case><from-outcome>logout</from-outcome><to-view-id>/pages/protected/user/listAllDogs.xhtml</to-view-id><redirect/></navigation-case></navigation-rule><navigation-rule><navigation-case><from-outcome>listAllDogs</from-outcome><to-view-id>/pages/protected/user/listAllDogs.xhtml</to-view-id></navigation-case></navigation-rule><navigation-rule><navigation-case><from-outcome>createDog</from-outcome><to-view-id>/pages/protected/admin/createDog.xhtml</to-view-id><redirect/></navigation-case></navigation-rule><navigation-rule><navigation-case><from-outcome>updateDog</from-outcome><to-view-id>/pages/protected/admin/updateDog.xhtml</to-view-id></navigation-case></navigation-rule><navigation-rule><navigation-case><from-outcome>deleteDog</from-outcome><to-view-id>/pages/protected/admin/deleteDog.xhtml</to-view-id></navigation-case></navigation-rule><application><resource-bundle><base-name>messages</base-name><var>msgs</var></resource-bundle></application></faces-config>

注意,對于某些操作,我使用了重定向操作。 通過此操作,我們將更新瀏覽器URL欄中的請求鏈接,URL更新后,JAAS將拒絕對非法用戶的訪問。

我們還有一個文件,其中包含我們系統(tǒng)的所有消息。 您會注意到,頁面中顯示的所有文本都在此文件中(在src文件夾中創(chuàng)建一個名為“ messages.properties”的文件):

#Dog dog=Dog dogName=Name dogWeight=Weight#Dog messages dogCreateHeader=Create a new Dog dogUpdateHeader=Update the Dog dogDeleteHeader=Delete this Dog dogNameRequired=The dog needs a name. dogWeightRequired=The dog needs a weight.#Actions update=Update create=Create delete=Delete cancel=Cancel#Login loginHello=Hello loginErrorMessage=Could not login. Check you UserName/Password loginUserName=Username loginPassword=Password logout=Log Out

視圖–創(chuàng)建和JSF設置

現(xiàn)在讓我們創(chuàng)建ManagedBeans。

首先,我們需要將EJB添加到Web項目中。 用鼠標右鍵單擊JSF項目>屬性:

Java構建路徑>項目>添加>檢查CrudEJB>確定

首先,讓我們創(chuàng)建DogMB:

package com.mb;import java.util.List;import javax.ejb.EJB; import javax.ejb.EJBException; import javax.faces.application.FacesMessage; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; import javax.faces.context.FacesContext;import com.facade.DogFacade; import com.model.Dog;@ManagedBean @RequestScoped public class DogMB {@EJBprivate DogFacade dogFacade;private static final String CREATE_DOG = 'createDog';private static final String DELETE_DOG = 'deleteDog';private static final String UPDATE_DOG = 'updateDog';private static final String LIST_ALL_DOGS = 'listAllDogs';private static final String STAY_IN_THE_SAME_PAGE = null;private Dog dog;public Dog getDog() {if(dog == null){dog = new Dog();}return dog;}public void setDog(Dog dog) {this.dog = dog;}public List<Dog> getAllDogs() {return dogFacade.findAll();}public String updateDogStart(){return UPDATE_DOG;}public String updateDogEnd(){try {dogFacade.update(dog);} catch (EJBException e) {sendErrorMessageToUser('Error. Check if the weight is above 0 or call the adm');return STAY_IN_THE_SAME_PAGE;}sendInfoMessageToUser('Operation Complete: Update');return LIST_ALL_DOGS;}public String deleteDogStart(){return DELETE_DOG;}public String deleteDogEnd(){try {dogFacade.delete(dog);} catch (EJBException e) {sendErrorMessageToUser('Error. Call the ADM');return STAY_IN_THE_SAME_PAGE;} sendInfoMessageToUser('Operation Complete: Delete');return LIST_ALL_DOGS;}public String createDogStart(){return CREATE_DOG;}public String createDogEnd(){try {dogFacade.save(dog);} catch (EJBException e) {sendErrorMessageToUser('Error. Check if the weight is above 0 or call the adm');return STAY_IN_THE_SAME_PAGE;} sendInfoMessageToUser('Operation Complete: Create');return LIST_ALL_DOGS;}public String listAllDogs(){return LIST_ALL_DOGS;}private void sendInfoMessageToUser(String message){FacesContext context = getContext();context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, message, message));}private void sendErrorMessageToUser(String message){FacesContext context = getContext();context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, message, message));}private FacesContext getContext() {FacesContext context = FacesContext.getCurrentInstance();return context;} }

關于上面的代碼:

  • 您將在faces-config.xml中找到所有導航。 您應該在頁面導航中使用常量或資源包; 與僅在方法中保留字符串相比,這種方法是一種更好的方法。
  • 注意,我們僅使用@EJB將EJB注入MB內(nèi)。 發(fā)生這種情況是因為我們正在使用同一個EAR中的所有東西。 JBoss 7使這種本地化變得容易。
  • 如果注入不適用于JBoss 6(或者在EAR之外使用EJB jar),則可以使用如下注入:@EJB(mappedName =“ DogFacadeImp / local”)。
  • 注意,將向我們的系統(tǒng)用戶顯示一條消息。 我們會對在Fa?ade中執(zhí)行的每個動作進行嘗試/捕獲,如果發(fā)生某些錯誤,我們將向用戶發(fā)送錯誤消息。
  • 正確的操作是驗證ManagedBean和Fa?ade中的數(shù)據(jù)。 這些驗證的CPU成本較低。
  • 如果您正在使用JBoss 4.2,則需要像下面的代碼那樣進行JNDI查找(就像本文前面所說的那樣,使用LocalBinding批注)。 像這樣注釋您的班級: @Stateless @LocalBinding(jndiBinding='MyBean') public class MyBeanImp implements MyBean{@Overridepublic String hello() {return 'Value From EJB';} } // In your Servlet class you would lookup like the code bellow: public class Inject extends HttpServlet {private MyBean local;protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {try {InitialContext iniCtx = new InitialContext();local = (MyBean) iniCtx.lookup('MyBean');} catch (NamingException e) {e.printStackTrace();}System.out.println(local.hello());request.getRequestDispatcher('/finish.jsp').forward(request, response);}/*** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {} }

現(xiàn)在,讓我們看看UserMB:

package com.mb;import javax.ejb.EJB; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; import javax.faces.context.ExternalContext; import javax.faces.context.FacesContext; import javax.servlet.http.HttpServletRequest;import com.facade.UserFacade; import com.model.User;@SessionScoped @ManagedBean public class UserMB {private User user;@EJBprivate UserFacade userFacade;public User getUser(){if(user == null){ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();String userEmail = context.getUserPrincipal().getName();user = userFacade.findUserByEmail(userEmail);}return user;}public boolean isUserAdmin(){return getRequest().isUserInRole('ADMIN');}public String logOut(){getRequest().getSession().invalidate();return 'logout';}private HttpServletRequest getRequest() {return (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();} }

關于上面的代碼:

  • 該MB僅用于存儲我們應用程序的會話用戶。 您將使用此MB顯示用戶名或有關應用程序用戶的任何其他操作。
  • 注意,這是一個會話MB; 我們只檢查一次用戶是否為null,如果返回true,我們將轉到數(shù)據(jù)庫。 在這種情況下,我們將只獲得一次數(shù)據(jù)庫保存性能。
  • 如果@EJB注入引發(fā)異常,請檢查上面DogMB中給出的技巧。

查看–頁面

下面是頁面,css及其各自的路徑:

不要介意上面圖片中顯示的詢問圖標或任何其他圖標類型。 這些是指向我的代碼的版本控制圖標。 始終保存您的代碼。

我在ManagedBean中使用RequestScope,這就是為什么您會在所有頁面中看到h:inputHidden的原因。 我認為用RequestScope MB重復此字段是一種更好的方法,因為您將擁有更多的可用內(nèi)存,而不是使用SessionScope MB。

/WebContent/resources/css/main.css

.table {border-collapse: collapse; }.tableColumnsHeader {text-align: center;background: none repeat scroll 0 0 #E5E5E5;border-bottom: 1px solid #BBBBBB;padding: 16px; }.tableFirstLine {text-align: center;background: none repeat scroll 0 0 #F9F9F9;border-top: 1px solid #BBBBBB; }.tableNextLine {text-align: center;background: none repeat scroll 0 0 #FFFFFFF;border-top: 1px solid #BBBBBB; }.panelGrid {border: 1px solid; }.panelFirstLine {text-align: center;border-top: 1px solid #BBBBBB; }.panelNextLine {text-align: center;border-top: 1px solid #BBBBBB; }

/WebContent/pages/public/login.xhtml

<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN''http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> <html xmlns='http://www.w3.org/1999/xhtml'xmlns:f='http://java.sun.com/jsf/core'xmlns:h='http://java.sun.com/jsf/html'xmlns:ui='http://java.sun.com/jsf/facelets'> <h:head><h:outputStylesheet library='css' name='main.css' /> </h:head> <h:body><p>Login to access secure pages:</p><form method='post' action='j_security_check'><h:messages layout='table' errorStyle='background: #AFEEEE;'infoStyle='background: #AFEEEE;' globalOnly='true' /><h:panelGrid columns='2'><h:outputLabel value='Username: ' /><input type='text' id='j_username' name='j_username' /><h:outputLabel value='Password: ' /><input type='password' id='j_password' name='j_password' /><h:outputText value='' /><h:panelGrid columns='1'><input type='submit' name='submit' value='Login' /></h:panelGrid></h:panelGrid><br /></form> </h:body> </html>

注意我們?nèi)绾蜗駥霂煲粯訉隿ss。 您在form標簽中看到的動作指向我們一個未知的動作,但是JAAS負責管理該動作。
/WebContent/pages/public/loginError.xhtml

<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN''http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> <html xmlns='http://www.w3.org/1999/xhtml'xmlns:f='http://java.sun.com/jsf/core'xmlns:h='http://java.sun.com/jsf/html'xmlns:ui='http://java.sun.com/jsf/facelets'> <h:head><h:outputStylesheet library='css' name='main.css' /> </h:head> <h:body>#{msgs.loginErrorMessage} </h:body> </html>

/WebContent/pages/protected/user/listAllDogs.xhtml

<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN''http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> <html xmlns='http://www.w3.org/1999/xhtml'xmlns:f='http://java.sun.com/jsf/core'xmlns:h='http://java.sun.com/jsf/html'xmlns:ui='http://java.sun.com/jsf/facelets'> <h:head><h:outputStylesheet library='css' name='main.css' /> </h:head> <h:body><h:form><h3>#{msgs.loginHello}: #{userMB.user.name} || <h:commandLink action='#{userMB.logOut()}' value='#{msgs.logout}' /> </h3><h:messages /><h:dataTable value='#{dogMB.allDogs}' var='dog' styleClass='table' headerClass='tableColumnsHeader' rowClasses='tableFirstLine,tableNextLine' ><h:column><f:facet name='header'>#{msgs.dogName}</f:facet>#{dog.name}</h:column><h:column><f:facet name='header'>#{msgs.dogWeight}</f:facet>#{dog.weight}</h:column><h:column><h:panelGrid columns='2'><!-- Always save the id as hidden when you use a request scope MB --><h:inputHidden value='#{dog.id}' /><h:commandButton action='#{dogMB.updateDogStart()}' value='#{msgs.update}' rendered='#{userMB.userAdmin}' ><f:setPropertyActionListener target='#{dogMB.dog}' value='#{dog}' /></h:commandButton><h:commandButton action='#{dogMB.deleteDogStart()}' value='#{msgs.delete}' rendered='#{userMB.userAdmin}' ><f:setPropertyActionListener target='#{dogMB.dog}' value='#{dog}' /></h:commandButton></h:panelGrid></h:column></h:dataTable><!-- This button is displayed to the user, just to you see the error msg --><h:commandButton action='createDog' value='#{msgs.create} #{msgs.dog}' /></h:form> </h:body> </html>

關于上面的代碼:

  • 永遠記得用h:form標記包裝代碼。 如果沒有h:form,h:head和h:body,有些框架(例如Primefaces)將無法工作。
  • 我們使用UserMB來顯示用戶名并注銷我們的用戶。
  • <h:messages />標記將顯示DogMB發(fā)送的消息。
  • 請注意,第33行的ID被隱藏。 如果您使用RequestScope而不是SessionScope,則這是一個必需的值。 我寧愿使用RequestScope也不使用SessionScope,因為服務器內(nèi)存中的數(shù)據(jù)更少。
  • 請注意,按鈕的呈現(xiàn)方式為=“#{userMB.userAdmin}”,以指示僅ADMIN角色有權訪問刪除/更新。
  • 我通過標簽“ f:setPropertyActionListener ”將選定的狗傳遞給我的MB。
  • “創(chuàng)建”按鈕沒有渲染選項。 如果普通用戶嘗試訪問頁面,它只是向您顯示。

/WebContent/pages/protected/admin/createDog.xhtml

<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN''http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> <html xmlns='http://www.w3.org/1999/xhtml'xmlns:f='http://java.sun.com/jsf/core'xmlns:h='http://java.sun.com/jsf/html'xmlns:ui='http://java.sun.com/jsf/facelets'> <h:head><h:outputStylesheet library='css' name='main.css' /> </h:head> <h:body><h:form><h:messages/><h3>${msgs.dogCreateHeader}</h3><h:panelGrid columns='2' styleClass='panelGrid' rowClasses='panelFirstLine,panelNextLine' ><h:outputLabel for='dogName' value='#{msgs.dogName}' /><h:inputText id='dogName' value='#{dogMB.dog.name}' required='true' requiredMessage='#{msgs.dogNameRequired}' /><h:outputLabel for='dogWeight' value='#{msgs.dogWeight}' /><h:inputText id='dogWeight' value='#{dogMB.dog.weight}' required='true' requiredMessage='#{msgs.dogWeightRequired}' ><f:convertNumber /></h:inputText></h:panelGrid><h:panelGrid columns='2'><h:commandButton action='#{dogMB.createDogEnd()}' value='#{msgs.create}' /><h:commandButton action='#{dogMB.listAllDogs()}' value='#{msgs.cancel}' immediate='true' /></h:panelGrid><br/></h:form> </h:body> </html>

關于上面的代碼:

  • 字段名稱和權重是必填字段,如果將其保留為空,則會顯示一條錯誤消息。
  • 取消按鈕需要選項Instant =“ true”; 使用此選項,JSF將不會驗證任何字段。

/WebContent/pages/protected/admin/deleteDog.xhtml

<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN''http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> <html xmlns='http://www.w3.org/1999/xhtml'xmlns:f='http://java.sun.com/jsf/core'xmlns:h='http://java.sun.com/jsf/html'xmlns:ui='http://java.sun.com/jsf/facelets'> <h:head><h:outputStylesheet library='css' name='main.css' /> </h:head> <h:body><h:form><h:messages/><h3>#{msgs.dogDeleteHeader}: #{dogMB.dog.name}?</h3><h:inputHidden value='#{dogMB.dog.id}' /><h:panelGrid columns='2'><h:commandButton action='#{dogMB.deleteDogEnd()}' value='#{msgs.delete}' /><h:commandButton action='#{dogMB.listAllDogs()}' value='#{msgs.cancel}' immediate='true' /></h:panelGrid><br/></h:form> </h:body> </html>

請注意,在第15行中,該ID是隱藏的。 如果您使用RequestScope而不是SessionScope,則這是一個必需的值。 我寧愿使用RequestScope也不使用SessionScope,因為服務器內(nèi)存中的數(shù)據(jù)更少。

/WebContent/pages/protected/admin/updateDog.xhtm l

<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN''http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> <html xmlns='http://www.w3.org/1999/xhtml'xmlns:f='http://java.sun.com/jsf/core'xmlns:h='http://java.sun.com/jsf/html'xmlns:ui='http://java.sun.com/jsf/facelets'> <h:head><h:outputStylesheet library='css' name='main.css' /> </h:head> <h:body><h:form><h:messages/><h3>#{msgs.dogUpdateHeader}: #{dogMB.dog.name}</h3><h:inputHidden value='#{dogMB.dog.id}' /><h:panelGrid columns='2' styleClass='panelGrid' rowClasses='panelFirstLine,panelNextLine' ><h:outputLabel for='dogName' value='#{msgs.dogName}' /><h:inputText id='dogName' value='#{dogMB.dog.name}' required='true' requiredMessage='#{msgs.dogNameRequired}' /><h:outputLabel for='dogWeight' value='#{msgs.dogWeight}' /><h:inputText id='dogWeight' value='#{dogMB.dog.weight}' required='true' requiredMessage='#{msgs.dogWeightRequired}' ><f:convertNumber /></h:inputText></h:panelGrid><h:panelGrid columns='2'><h:commandButton action='#{dogMB.updateDogEnd()}' value='#{msgs.update}' /><h:commandButton action='#{dogMB.listAllDogs()}' value='#{msgs.cancel}' immediate='true' /></h:panelGrid><br/></h:form> </h:body> </html>

關于上面的代碼:

  • 請注意,在第15行中,該ID是隱藏的。 如果您使用RequestScope而不是SessionScope,則這是一個必需的值。 我寧愿使用RequestScope也不使用SessionScope,因為服務器內(nèi)存中的數(shù)據(jù)更少。
  • 字段名稱和權重是必填字段,如果將其保留為空,則會顯示一條錯誤消息。
  • 取消按鈕需要選項Instant =“ true”; 使用此選項,JSF將不會驗證任何字段。

查看– JBoss 7 JAAS配置

現(xiàn)在,我們只需要完成一些步驟即可完成我們的軟件(最后!)。

我們需要編輯JBoss配置并添加我們的JAAS配置。

再次打開文件“ YOUR_JBOSS / standalone / configuration / standalone.xml ”,然后搜索密鑰:“ <security-domains>”。 添加下面的代碼(在這篇文章中,我演示如何為JBoss 6 – 使用JAAS和JSF進行用戶登錄驗證 )進行設置:

<subsystem xmlns='urn:jboss:domain:security:1.0'><security-domains><!-- add me: begin --><security-domain name='CrudJSFRealm' cache-type='default'><authentication><login-module code='org.jboss.security.auth.spi.DatabaseServerLoginModule' flag='required'><module-option name='dsJndiName' value='CrudDS'/><module-option name='principalsQuery' value='select password from users where email=?' /><module-option name='rolesQuery' value='select role, 'Roles' from users u where u.email=?' /></login-module></authentication></security-domain><!-- add me: end --><!-- Other data... --></security-domains> </subsystem>

運行我們的應用程序

讓我們創(chuàng)建一個EAR來統(tǒng)一我們的項目。

文件>新建>其他> EnterpriseApplication項目

我們只需要在我們的JBoss中添加EAR。

讓我們運行我們的應用程序。 啟動JBoss并通過以下URL訪問我們的應用程序: http:// localhost:8080 / CrudJSF / 。

我使用簡單CSS編寫了頁面,以使理解更加容易。

以USER身份登錄,您將不會看到更新/刪除按鈕; 您只會看到我們留在此處的“創(chuàng)建”按鈕,只是為了查看非法訪問的例外情況。

看一下我們的頁面:

記錄為ADMIN:

以USER身份登錄:

今天就這些

要下載此帖子的源代碼, 請單擊此處 。

希望這篇文章對您有所幫助。

如果您有任何疑問或評論,請在下面將其發(fā)布。

再見。 \ o_

對我有幫助的鏈接:

http://7thursdays.wordpress.com/2008/03/18/dependency-injection-in-jboss-42-hold-your-excitement/

http://jan.zawodny.pl/blog/2011/07/jboss-7-postgresql-9

http://blog.xebia.com/2011/07/19/developing-a-jpa-application-on-jboss-as-7/

http://community.jboss.org/wiki/DataSourceConfigurationInAS7

http://stackoverflow.com/questions/286686/how-to-create-conditions-based-on-user-role-using-jsf-myfaces/

http://www.mkyong.com/jsf2/jsf-2-datatable-example/

參考: uaiHebert博客上來自我們的JCG合作伙伴 Hebert Coelho的完整WebApplication JSF EJB JPA JAAS 。


翻譯自: https://www.javacodegeeks.com/2012/06/full-webapplication-jsf-ejb-jpa-jaas_19.html

總結

以上是生活随笔為你收集整理的完整的WebApplication JSF EJB JPA JAAS –第2部分的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。