English 中文(简体)
春季MVC 3和验证错误
原标题:Spring MVC 3 and validation error

我试图用基于 Spring MVC 的 Javax 来创建简单的验证。 我启用了批注驱动程序 。 我想在表格中显示错误, 但有500页错误 :

< 加强> 500 错误页面

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors
Field error in object  profile  on field  email : rejected value [xx@ss]; codes [Pattern.profile.email,Pattern.email,Pattern.java.lang.String,Pattern]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [profile.email,email]; arguments []; default message [email],[Ljavax.validation.constraints.Pattern$Flag;@718df055,^[_A-Za-z0-9-]+(.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(.[A-Za-z0-9]+)*(.[A-Za-z]{2,})$]; default message [Nieprawidłowy e-mail]
Field error in object  profile  on field  login : rejected value [xx]; codes [Size.profile.login,Size.login,Size.java.lang.String,Size]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [profile.login,login]; arguments []; default message [login],20,4]; default message [Login musi min. długość 4 znaków, max. 20 znaków]
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

<强 > 主计长

@RequestMapping(value="/register", method=RequestMethod.POST)
    public String register(
            @Valid Profile profile,
            @RequestParam("recaptcha_challenge_field") String challenge,
            @RequestParam("recaptcha_response_field") String response, 
            BindingResult result, Model model, HttpServletRequest request) {

        ReCaptchaResponse cResponse = captcha.checkAnswer(request.getRemoteAddr(), challenge, response);
        if(result.hasErrors() || !cResponse.isValid()) {
            String message = cResponse.getErrorMessage();
            String html = captcha.createRecaptchaHtml(message, null);
            model.addAttribute("profile", profile);
            model.addAttribute(CAPTCHA_HTML, html);
            return "login/register";
        }
        return "ok";
    }

<强 > 模型的一部分(只有此字段被验证)

@NotBlank
    @Size(min=4, max=20)
    @Pattern(regexp="^([\w]+)$")
    private String login;

    @NotBlank
    @Pattern(regexp=("^[_A-Za-z0-9-]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$"))
    private String email;

如何解决这个问题?

最佳回答

也许尝试做maven清洁 并安装到你的本地回购?

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签