使用错误标记时以jsp形式显示错误

时间:2014-09-12 08:30:55

标签: java spring jsp

我正在开发一个项目'表单验证'在eclipse中使用Spring框架。在表单创建的jsp页面中,当包含tag时显示错误。当鼠标悬停在它上面时显示"在此行找到多个注释:      - 列表是原始类型。对泛型类型列表的引用应该是      参数"

myform.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Registration Page</title>
<style>
.error {
    color: #ff0000;
    font-style: italic;
}
</style>
</head>
<body>

<form:form method="POST" commandName="user">
    <table>
        <tr>
            <td>Enter User Name :</td>
            <td><form:input path="name" /></td>
            <td><form:errors path="name" cssClass="error" /></td>
        </tr>
        <tr>
            <td>Enter Degree :</td>
            <td><form:input path="degree" /></td>
            <td><form:errors path="degree" cssClass="error" /></td>
        </tr>
        <tr>
            <td>Enter Mark :</td>
            <td><form:input path="mark" /></td>
            <td><form:errors path="mark" cssClass="error" /></td>
        </tr>
        <tr>
            <td>Enter Address :</td>
            <td><form:input path="address" /></td>
            <td><form:errors path="address" cssClass="error" /></td>
        </tr>
        <tr>
            <td>Enter Mail ID :</td>
            <td><form:input path="mail" /></td>
            <td><form:errors path="mail" cssClass="error" /></td>
        </tr>

        <tr>
            <td colspan="3"><input type="submit" value="Register"></td>
        </tr>
    </table>
</form:form>

</body>
</html>

validation.java:

package com.validation;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;



import com.validation.Student;

public class StudentValidator implements Validator {

    public boolean supports(Class<?> clazz) {
        return Student.class.isAssignableFrom(clazz);
    }

    public void validate(Object target, Errors errors) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name",
                "name.required");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "degree",
                "degree.required");
        ValidationUtils.rejectIfEmpty(errors, "mark", "mark.required");
        ValidationUtils.rejectIfEmpty(errors, "address", "address.required");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "mail",
                "mail.required");

        @SuppressWarnings("unused")
        Student user = (Student) target;

    }

}

任何人都可以告诉它有什么问题吗?

0 个答案:

没有答案