Architecting Applications for the Web Lab04 Struts – OGNL,Validation and Internationalization Mục tiêu - Sử dụng OGNL, Validation Internationalization xây dựng ứng dụng Web Phần I Bài tập step by step Bài tập: Phần 1: OGNL: Sử dụng ValueStack, OGNL expression, converter sử dụng để xây dựng ứng dụng Lap Phần 2: Xây dựng validation cho trang đăng ký User(register) public void validate() { if (this.userName.length() == 0) { addFieldError("userName", "UserName is required"); } else if (this.userName.length() < || this.userName.length() > 50) { addFieldError("userName", "Length's username is required from to 50 characters"); } if (this.password.length() == 0) { addFieldError("password", "Password is required"); } else if (this.password.length() < || this.password.length() > 30) { addFieldError("password", "Length's password is required from to 30 characters"); } if (this.confirmpassword.length() == 0) { addFieldError("confirmpassword", "ConfirmPassword is required"); } else if (this.confirmpassword != this.password){ addFieldError("confirmpassword", "Password and ConfirmPassword not match"); } if (this.firstName.length() == 0) { addFieldError("firstName", "FirstName is required"); } else if (this.firstName.length() > 50 ) { addFieldError("firstName", "Length's firstName is required less 50 characters"); } if (this.lastName.length() == 0) { addFieldError("lastName", "LastName is required"); } else if (this.lastName.length() > 50 ) { addFieldError("lastName", "Length's lastName is required less 50 characters"); } } Phần 3: Sử dụng Internationalization i18n để xây dựng trang login đa ngôn ngữ Step 1: Xây dựng trang login_lang.jsp IT Research Department @BKAP 2015 Trang / Architecting Applications for the Web en fr English France Step 2: Xây dựng global Resource Bundle global_en.properties login.here = Login login.username = UserName login.password = Password login.submit = Login login.link1 = Are you new users? Click login.link2 = here login.link3 = to create new user global_fr.properties login.here = Connectez-vous login.user = Nom d'utilisateur login.password = Mot de passe login.submit = Connexion login.link1 = Êtes-vous de nouveaux utilisateurs? Cliquez login.link2 = ici login.link3 = pour créer un nouvel utilisateur Step 3: Cấu hình struts.xml … … /employee.jsp …… Struts.xml IT Research Department @BKAP 2015 Trang / Architecting Applications for the Web useriformation.jsp loginfailure.jsp /employee.jsp > register.jsp success.jsp error.jsp searchuser.jsp SearchUser SearchUser Step 4: Build and Run IT Research Department @BKAP 2015 Trang / ... ... name="defaultStack"/> SearchUser Step 4: Build and Run IT Research Department @BKAP 2015 Trang /