spring3 MVC jquery ajax under the combination of simple to use - Super Simple

Today need to write a simple application: user registration, check the user name is available.

Seemingly on the next before struts2 ajax support is good (actually irritated), and there are many online tutorials. But this is replaced springmvc, and it is spring3, few things online.

However, the discovery or springsource article .

The client uses the formValidtor plug, this plug-in is really good, huh, huh.

$("#loginName").formValidator({onshow:" Please enter a user name  ",onfocus:" The user name for at least 6 characters  , Up to 15 characters  ",oncorrect:" The username you can register  "}).inputValidator({min:6,max:15,onerror:" Did you enter the name of illegal, please confirm  "}).regexValidator({regexp:"username",datatype:"enum",onerror:" User name is not in the correct format  "}).ajaxValidator({
            type : "get",
                url : "${ctx}/ajax/checkLoginName",
                datatype : "json",
                success : function(data){
            if( data == "1" )
                return true;
                return false;
                buttons: $("#button"),
                error: function(){alert(" The server did not return the data, perhaps the server is busy  , Please try again  ");},
                onerror : " The user name is not available, please change username  ",
                onwait : " The user name to validate, please wait  ..."

This is formValidator ajax form validation that comes with very clear.

In the article, found on the plot of a foreigner can have a more simple way ajax call:

jQuery.getJSON( url, [ data ], [ callback(data, textStatus) ] )

Known from jquey website:

This is a shorthand Ajax function, which is equivalent to:

  url: url,
  dataType: 'json',
  data: data,
  success: callback

Corresponds to the server can be too cool, and really is a standard spring control! ! ! !

public class CommonServControl {

        @RequestMapping(value = "/checkLoginName", method = RequestMethod.GET)
        public @ResponseBody boolean checkLoginName(@RequestParam String loginName) {
                boolean b = userServ.checkLoginName(loginName);
                return b;

        private UserServ userServ;


I believe this code is enough "POJO" instead.

Of course, pay attention! ! ! This is not enough!


Underneath the covers, Spring MVC delegates to a HttpMessageConverter to perform the serialization. In this case, Spring MVC invokes a MappingJacksonHttpMessageConverter built on the Jackson JSON processor. This implementation is enabled automatically when you use the mvc: annotation-driven configuration element with Jackson present in your classpath.

This passage means, spring use "HttpMessageConverter" to work, so we need to do one thing:

In springMVC's XXX-servlet.xml file by adding such a line:

<mvc:annotation-driven />

 Namespace  :
<beans xmlns="http://www.springframework.org/schema/beans"
        xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
                http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

OK bin!

This is a post in a way which is almost, huh, huh

1. $( "#account" ).submit( function () {

2. var account = $( this ).serializeObject();

3. $.postJSON( "account" , account, function (data) {

4. $( "#assignedId" ).val(data.id);

5. showPopup();

6. });

7. return false ;

8. });

On the server-side, the Controller is more standard Java with Spring MVC annotations:

view source

Print ?

01. @RequestMapping (method=RequestMethod.POST)

02. public @ResponseBody Map<String, ? extends Object> create( @RequestBody Account account, HttpServletResponse response) {

03. Set<ConstraintViolation<Account>> failures = validator.validate(account);

04. if (!failures.isEmpty()) {

05. response.setStatus(HttpServletResponse.SC_BAD_REQUEST);

spring mvc bind the entity under the editor submitted a solution for ...

  • 21:06
  • View (0)
  • Comments (0)
  • Category: Education Management System
  • Related recommendations

spring3 MVC jquery ajax under the combination of simple to use - Super Simple


  • View: 3013 times
  • Gender:
  • From: Hangzhou
  • Details book
Search this blog
Recent visitors>> More Visitors





Blog Categories
  • All blog (28)
  • Database (3)
  • JAVA (3)
  • CSS (0)
  • IDE (1)
  • Spring (4)
  • Struts2 (2)
  • hibernate (3)
  • Miscellaneous notes (2)
  • freemarker (1)
  • Education Management System (9)
Other Categories
  • My Favorites (21)
  • My forum topics posted (0)
  • I posted all the forums (7)
  • I am the essence of a good paste (0)
  • I solved the problem (1)
Recently joined the circle
  • GT-Grid
  • 2010-04 (3)
  • 2010-03 (2)
  • 2010-02 (2)
  • More archives ...
Latest Comments
  • Use the annotation to reduce spring ...
    I am here to ask to use @ Autowired access serivce when the database operation ...
    - By Zhu Yuanyu
  • The basics of MySQL and I used in the design development tool, although not very familiar with, but the software will automatically choose the more appropriate type of data table ...
    - By poplar1986
Comments list
  • Use the annotation to reduce spring bean configuration
  • java file path summary (change)
  • freemark few tips
  • 3.2 Specific technology-fckeditor2.6
  • 3.1 Specific technology - related pages

分类:Java 时间:2010-04-13 人气:1091
blog comments powered by Disqus


  • JQuery's json functionality expansion 2009-06-16

    In this paper, based on jQuery expanded its capacity to deal with json string, great jQuery will be great, ha ha! Writing javascript with jQuery is very efficient, jQuery for ajax package also in place; using jQuery after a certain period of time, jQ

  • servlet + jquery ajax + json demo 2010-07-16

    1. The corresponding jar package imports. Json-lib-2.2.3-jdk15.jar, ezmorph-1.0.6.jar so. 2. Join jquery.js 3. Jquery each () method to use api. http://api.jquery.com/jQuery.each/ 4. Server servlet program import javax.servlet.http.HttpServlet; impor

  • Struts2 + jQuery + ajax + json example 2011-07-20

    struts2 + jquery + json + ajax application, write down, and after the backup. 1 Environment jquery: jquery-1.6.2.min.js struts2: Basic package is not said, to talk about the application json package, mainly struts2-json-plugin- json: json

  • asp.net中利用Jquery+Ajax+Json实现无刷新分页的实例代码 2014-04-24

    本篇文章主要是对asp.net中利用Jquery+Ajax+Json实现无刷新分页的实例代码进行了介绍,需要的朋友可以过来参考下,需要对大家有所帮助 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="AjaxJson.aspx.cs" Inherits="AjaxJson" %> <!DOCTYPE html PUBLIC "-//W3C

  • JQuery处理json与ajax返回JSON实例代码 2014-09-08

    json数据是一种经型的实时数据交互的数据存储方法,使用到最多的应该是ajax与json配合使用了,下面我来给大家介绍jquery处理json数据方法 一.JSON的一些基础知识. JSON中对象通过"{}"来标识,一个"{}"代表一个对象,如{"AreaId":"123"},对象的值是键值对的形式(key:value). "[]",标识数组,数组内部各个数据之间通过","分割,如[&q

  • php+jquery+ajax+json示例 2011-03-02

    客户端代码ajax_client.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta htt

  • Ajax+json+jquery实现无限瀑布流布局 2012-08-19

    Ajax+json+jquery实现无限瀑布流布局 <!doctype html> <html> <head> <meta charset="utf-8"> <title>定宽Jquery+AJAX+JSON瀑布流布局(每行代码都有详细注释)</title> <style type="text/css"> body, ul, li, h3 { margin: 0; padding:

  • Highcharts AJAX JSON JQuery 实现动态数据交互显示图表 柱形图 2014-12-05

    这是第一篇实例的步骤与代码.还有整个项目的结构图. http://my.codeweblog.com/xshuai/blog/345117 原创的博文.转载注明出处.大家赶紧收藏吧. 本人highcharts新手.只是做个了练手的实例.还望大神指点. 上个图给大家看下效果. 点击 查看图表 如下图展示效果 Highcharts简介 Highcharts 是一个用纯JavaScript编写的一个图表库, 能够很简单便捷的在web网站或是web应用程序添加有交互性的图表,并且免费提供给个人学习.个人

  • struts2 + jquery + ajax + json + struts2_json_plugin configuration example 2011-01-01

    1.struts.xml <constant name="struts.i18n.encoding" value="utf-8" /> <package name="jsondefault" namespace="/json" extends="json-default"> <action name="loginByAjax"> <result

  • jquery获取url参数--jquery.query 2013-03-27

    jquery获取url参数--jquery.query 用法: 1.引用 <script type="text/javascript" src="js/jquery.query.js"></script> <script type="text/javascript"> var jQuery.query = { numbers: false, hash: true }; </script> 2.获取u

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 闽ICP备15018612号

processed in 0.248 (s). 13 q(s)