배경 : Struts2를 REST 및 Convention 플러그인과 함께 사용하고 있기 때문에 설정의 약 99 %가 내가 쓰는 클래스에 있고 xml 파일에는없는 것입니다. 협약에, 당신은 방법에 주석으로 서버와 클라이언트 측 검증을 구성 할 수 있습니다, 예를 들어, 계정 방법을 만들어이 같은 모양을 사용하고 있습니다 :Struts2 유효성 검사 인터셉터가 xhtml 문서로 이동
@Validations(
requiredFields = {
@RequiredFieldValidator(type = ValidatorType.SIMPLE, fieldName = "userName", message = "You must enter a value for field."),
@RequiredFieldValidator(type = ValidatorType.SIMPLE, fieldName = "firstName", message = "You must enter a value for field."),
@RequiredFieldValidator(type = ValidatorType.SIMPLE, fieldName = "lastName", message = "You must enter a value for field."),
@RequiredFieldValidator(type = ValidatorType.SIMPLE, fieldName = "password", message = "You must enter a value for field.")
},
emails = {@EmailValidator(type = ValidatorType.SIMPLE, fieldName = "email", message = "You must enter a value for email.")},
stringLengthFields = {
@StringLengthFieldValidator(type = ValidatorType.SIMPLE, trim = true, minLength = "6", maxLength = "16", fieldName = "userName", message = "Username must be at least 6 letters."),
@StringLengthFieldValidator(type = ValidatorType.SIMPLE, trim = true, minLength = "8", maxLength = "16", fieldName = "password", message = "Password must be at least 8 characters.")
}
)
public String create() {
//create the account
}
이 좋은 작품, 자바 스크립트가 제대로 밀어 JSP로 제출하기 전에 양식이 유효성 검사를 받고 서버 측 유효성 검사가 잘 작동합니다. 모든 조건이 충족되면 create()
메소드가 올바르게 호출되고 모든 것이 작동합니다.
클라이언트 쪽 유효성 검사가 무시되고 서버 쪽 유효성 검사가 실패 할 때 문제가 발생합니다. 모든 문서에서 Validation 인터셉터는 사용자가 문제를 해결할 수 있도록 적절한 필드 오류가 설정된 양식으로 사용자를 보냈지 만 내 앱에서는 완전히 빈 페이지로 리디렉션된다는 것을 알 수 있습니다.
질문 0 : - 양식을 리디렉션 할 위치를 확인 인터셉터에게 알려서 값을 채울 수 있고 fieldErrors를 올바르게 설정할 수 있도록하려면 어떻게해야합니까?