English 中文(简体)
移动 Spring3 MVC 错误到 Ajax?
原标题:Moving Spring3 MVC Errors to Ajax?

我正在研究一个项目,在Spring-MVC项目中添加一些Ajax。

<form:errors path="fieldName"/>

这将插入 JSP 错误, 现在我试图做一些 Ajax 代码来显示页面上的错误。 有人能让我如何更新以下代码来显示错误信息而不是错误吗?

success: function(response)
          {
          // we have the response 
            $( #error ).hide( fast );   
            if(response.status == "SUCCESS")
            {
                $( #error ).hide( fast );  
                alert("Thanks for submitting.  We will get back to you as soon as possible.

" + response.result);
                $( #error ).hide( slow );

            时 时else
            {
              errorInfo = "";
              for( i = 0 ; i < response.result.length ; i++){
                  errorInfo += "<br>" + (i + 1) +". " + response.result[i].code;
              时 时
              $( #error ).html("Please correct following errors: " + errorInfo);
              $( #info ).hide( slow );
              $( #error ).show( slow );
              $( #input ).show( slow );
          时 时       
        时 时,  
        error: function(e){  
          alert( Error:   + e);  
        时 时  
      时 时);  

上述代码用来显示错误, 而不是错误信息

下面是我的 Java 代码 :

    @RequestMapping(value = "/ajax.html", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponse addMessage(@Valid
            @ModelAttribute(value = "memberrequest") MemberRequest memberrequest,
            BindingResult result) {

            JsonResponse res = new JsonResponse();


        if (!result.hasErrors()) {
            res.setStatus("SUCCESS");

            // Setting data over to RT

            String Ticket = zzz.sentWebRequest(memberrequest);

            /*
             * Setting out the ticket number to be displayed to user
             */

            Map<String, Object> model = new HashMap<String, Object>();
            Ticket t = new Ticket();
            t.setTicketDetails(Ticket);

            model.put("ticket", t);

            res.setResult(Ticket);
        时 时 else {
            res.setStatus("FAIL");
            res.setResult(result.getAllErrors());
        时 时

        return res;
    时 时
时 时

JSON类:

public class JsonResponse { private String status = null; private Object result = null;

公共字符串获取状态 () { 返回状态;时 时

公共无效设置状态( Status (String status)) { { this. status = status;时 时

公共对象获得Result () { 返回结果;时 时

公共无效设置Result( 对象结果) {此处。 结果=结果;时 时

时 时

最佳回答

尝试 response. 结果。 默认邮件 而不是 < code> reponse. l. code .

问题回答
response.result

根据 reponse 对象中不存在 结果 属性 reponses





相关问题
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 ...