The request sent by the client was syntactically incorrect

This seems to be a common error during form submission in Spring WebMVC. Hence finding the root cause behind this may be difficult.

I verified step by step and confirmed that my call reaches my controller. But it breaks with the following error.

400 The request sent by the client was syntactically incorrect

Rightly pointed out at http://stackoverflow.com/questions/20616319/the-request-sent-by-the-client-was-syntactically-incorrect-spring-mvc-jdbc-te this is my date issue. I had a date field in my form. You can check my previous post on how to add jQuery date picker.

Hence, I need to make some modifications.

I added the following initBinder() method in the controller.

@RequestMapping(value="/add_expense", method=RequestMethod.POST)
    public String addExpense(@ModelAttribute ExpenseDetail expenseDetail, Model model) {
        try {
            System.out.println("===> returning add_expense"+expenseDetail.getExpenseCurrency());
            model.addAttribute("expenseList", new ExpenseDAO().getExpenseRecords());
            model.addAttribute("expenseDetail", new ExpenseDetail());
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return "home";
    }
    
    public void initBinder(WebDataBinder binder){
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
        sdf.setLenient(true);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));
    }

28-1406550815-malarmalaikal

Enjoy!

Advertisements

jquery – starter tutorial #4

If you haven’t checked the previous posts, please check the following
jquery – starter tutorial #3
jquery – starter tutorial #2
jquery – starter tutorial #1

We can more styles and animations. But I am too lazy to write all of those items here. But I feel I like to make a note of AJAX requests. One of the example below

<html>
<head>
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    $("div").load('01.html');
  });
});
</script>
</head>
<body>

<div><h2>Let AJAX change this text</h2></div>
<button>Change Content</button>

</body>
</html>

 

jquery – starter tutorial #3

If you haven’t checked the previous posts, please check the following
jquery – starter tutorial #2
jquery – starter tutorial #1

This post will give you more on the animation and design functions of jquery.

<html>
<head>
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
      $("#hide").click(function(){
        $(".hide").hide();
        $(".show").hide();
      });
    });

    $(document).ready(function(){
      $("#show").click(function(){
        $(".hide").show("slow");
        $(".show").show("fast");
      });
    });

    $(document).ready(function(){
      $("#toggle").click(function(){
        $(".toggle").slideToggle();
      });
    });

    $(document).ready(function(){
      $("#animate").click(function(){
        $("div").animate({height:300},"slow");
    $("div").animate({width:300},"slow");
    $("div").animate({height:100},"slow");
    $("div").animate({width:100},"slow");
      });
    });

    $(document).ready(function(){
      $("#fadeTo").click(function(){
        $(".fadeTo").fadeTo("slow",0.25);
      });
    });

</script>

</head>
<body>
<button id="hide">hide</button>
<button id="show">show</button>
<button id="toggle">toggle</button>
<button id="fadeTo">fadeTo</button>
<button id="animate">animate</button>

<div>show me</div>
<div>hide me</div>
<div>toggle me</div>
<div style="background:yellow;">fadeTo me</div>
<div style="background:#98bf21;height:100px;width:100px;position:relative">animate me</div>

</body>
</html>

Click the buttons to see the methods in action.

jquery – starter tutorial #2

If you have not checked #1, please check jquery – starter tutorial #1

This post will give more info on selectors and introduction to styles.

<html>
<head>
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
      $("p.heading").click(function(){
        $(this).hide("slow");
      });
    });

    $(document).ready(function(){
      $("#list").click(function(){
        $(this).hide("fast");
      });
    });

    $(document).ready(function(){
      $("#showAll").click(function(){
        $("p.heading").show("slow");
        $("#list").show("fast");
      });
    });

</script>

</head>
<body>
<h1>India lives</h1>
<p>on families</p>
<p>and their savings</p>
<p>and their believes</p>
Whats is fake?:
<ul id="list">
<li>Worst Politics</li>
<li>Criminal Politicians</li>
<li>Highly paid corrupted and unskilled govt employees</li>
</ul>
<p id="showAll"> <a href="javascript:void()">Show all elements </a></p>
</body>
</html>

Load this on the browser, click on the contents! See the jquery magic

$(“*”) selects all elements.

$(“p”) selects all <p> elements.

$(“p.intro”) selects all <p> elements with the class intro

$(“p#intro”) selects the first <p> elements with id=”intro”.

$(“:animated”) selects all elements that are currently animated.

$(“:button”) selects all <button> elements and <input> elements of type=”button”.

$(“:even”) selects even elements.

$(“:odd”) selects odd elements.

 

jquery – starter tutorial #1

To start with jquery is a simpler task. To use jquery is a fun. Here is a starter.

$ refers to jquery

$(this).hide()
Demonstrates the jQuery hide() method, hiding the current HTML element.

$(“#test”).hide()
Demonstrates the jQuery hide() method, hiding the element with id=”test”.

$(“p”).hide()
Demonstrates the jQuery hide() method, hiding all <p> elements.

$(“.test”).hide()
Demonstrates the jQuery hide() method, hiding all elements with.

<html>
<head>
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("p").click(function(){
    $(this).hide();
  });
});

$(document).ready(function(){
  $("#idtest").click(function(){
    $(this).hide();
  });
});

$(document).ready(function(){
  $(".classtest").click(function(){
    $(this).hide();
  });
});

</script>
</head>
<body>
<p>If you click on me, I will disappear.</p>
<p>Click me away!</p>
<p>Click me too!</p>
<div id="idtest">hide this div with id idtest</div>
<span>hide this span with classtest idtest</span>
</body>
</html>