vi du ajax validation trong struts 2

5 131 0
vi du ajax 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 ajax Validation Struts Struts cung cấp hỗ trợ cho AJAX Validation Trong trường hợp này, page khơng refresh reload, điều làm tăng hiệu suất Nó thực ngầm định sử dụng JavaScript, ví dụ: sử dụng cho trình Validation Client-Side Để sử dụng AJAX Validation, bạn cần thêm dojo plugin project bạn Giới thiệu jsonValidation Interceptor AJAX Validation thực jsonValidation Interceptor Nó khơng tìm thấy default stack, bạn cần định nghĩa cách tường minh Chính khơng thực trình validation nào, phải sử dụng với Validation Interceptor Nó tìm thấy jsonValidationWorkflowStack, mà bao gồm jsonValidation, validation workflow interceptor basicstack Các bước để thực AJAX Validation  Tạo form để lấy input từ người dùng  Kế thừa lớp ActionSupport action bạn  Định nghĩa validation validation.xml file  Định nghĩa result name cho thông điệp lỗi đăng ký jsonValidationWorkflowStack struts.xml file Ví dụ để thực AJAX Validation Trong ví dụ này, tạo page, sau: Tạo index.jsp Cho input từ người dùng Nó nhận name, password, email id từ người dùng http://vietjack.com/ Trang chia sẻ học online miễn phí Page http://vietjack.com/struts_2/index.jsp Copyright © vietjack.com Registration Form Tạo lớp action : Lớp kế thừa lớp ActionSupport ghi đè phương thức validate RegisterAction.java package mypack; import com.opensymphony.xwork2.ActionSupport; public class Register extends ActionSupport{ private String name,password,email; //Phuong thuc setter va getter 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 Email ID khong duoc de trong Xin nhap mot email id hop le Password khong duoc de trong 5 http://vietjack.com/ Trang chia sẻ học online miễn phí Page http://vietjack.com/struts_2/index.jsp Copyright © vietjack.com 10 Password khong the it hon hoac dai hon 10 Tạo struts.xml xml file định nghĩa result tên nhập, interceptor jsonValidatorWorkflowStack /welcome.jsp /index.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 http://vietjack.com/ Trang chia sẻ học online miễn phí Page http://vietjack.com/struts_2/index.jsp Copyright © vietjack.com Welcome, http://vietjack.com/ Trang chia sẻ học online miễn phí Page ... ?> ... 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

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

Từ khóa liên quan

Mục lục

  • ajax Validation trong Struts 2

    • Giới thiệu jsonValidation Interceptor

    • Các bước để thực hiện AJAX Validation

    • Ví dụ để thực hiện AJAX Validation

      • 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

  • Đang cập nhật ...

Tài liệu liên quan