vi du stringlength validation trong struts 2

5 136 0
vi du stringlength validation trong struts 2

Đang tải... (xem toàn văn)

Thông tin tài liệu

http://vietjack.com/struts_2/index.jsp Copyright © vietjack.com stringlength Validation Struts stringlength Validator xác định chuỗi phải có độ dài xác định Nó sử dụng username, password, … Theo mặc định, cắt tỉa (bởi tham số trim) chuỗi cho sau kiểm tra xem độ dài chuỗi độ dài cho không Các tham số stringlength Validator Struts Có tham số định nghĩa cho stringlength Validator, là:  fieldName: xác định tên trường mà để validate Nó bắt buộc Plain-Validator  minLength: xác định độ dài tối thiểu Theo mặc định, bỏ qua  maxLength: xác định độ dài tối đa Theo mặc định, bỏ qua  trim: cắt tỉa giá trị trường Theo mặc định true, nghĩa đươc kích hoạt theo mặc định Ví dụ stringlength validation Cho Plain Validator: password 6 10 true Password phai tu den 10 ky tu Cho Field Validator: http://vietjack.com/ Trang chia sẻ học online miễn phí Page http://vietjack.com/struts_2/index.jsp Copyright © vietjack.com 6 10 true Password phai tu den 10 ky tu Ví dụ đầy đủ stringlength validation Struts Tạo index.jsp Cho input từ người dùng Nó nhận name, password, email id từ người dùng errorMessage{color:red;} http://vietjack.com/ Trang chia sẻ học online miễn phí Page http://vietjack.com/struts_2/index.jsp Copyright © vietjack.com Tạo lớp action : Lớp kế thừa lớp ActionSupport ghi đè phương thức validate RegisterAction.java package com.vietjack; import com.opensymphony.xwork2.ActionSupport; public class Register extends ActionSupport{ private String username,userpass; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getUserpass() { return userpass; } public void setUserpass(String userpass) { this.userpass = userpass; } public String execute(){ return "success"; } } http://vietjack.com/ Trang chia sẻ học online miễn phí Page http://vietjack.com/struts_2/index.jsp Copyright © vietjack.com Tạo validation file Tại sử dụng bundled validator để thực trình validation Register-validation.xml Name khong duoc de trong Password khong duoc de trong 6 10 Password phai lon hon hoac bang va nho hon hoac bang 10 http://vietjack.com/ Trang chia sẻ học online miễn phí Page http://vietjack.com/struts_2/index.jsp Copyright © vietjack.com Tạo struts.xml xml file định nghĩa result tên nhập, interceptor jsonValidatorWorkflowStack index.jsp welcome.jsp Tạo thành phần view JSP file đơn giản hiển thị thông tin người dùng welcome.jsp Welcome, http://vietjack.com/ Trang chia sẻ học online miễn phí Page ... ... http://vietjack.com/ Trang chia sẻ học online miễn phí Page http://vietjack.com /struts_ 2/ index.jsp Copyright © vietjack.com Tạo validation file Tại sử dụng bundled validator để thực trình validation. .. http://vietjack.com/ Trang chia sẻ học online miễn phí Page http://vietjack.com /struts_ 2/ index.jsp Copyright © vietjack.com Tạo struts. xml xml file định nghĩa

Ngày đăng: 02/12/2017, 21:05

Từ khóa liên quan

Mục lục

  • stringlength Validation trong Struts 2

    • Các tham số của stringlength Validator trong Struts 2

    • Ví dụ stringlength validation

    • Ví dụ đầy đủ stringlength validation trong Struts 2

      • Tạo index.jsp

      • Tạo lớp action

      • Tạo validation file

      • Tạo struts.xml

      • Tạo các thành phần view

Tài liệu cùng người dùng

Tài liệu liên quan