How to POST and GET JSON between EXTJS and SpringMVC3

After one month of evaluation of the frameworks and tools, i choose ExtJS for UI and Spring/SpringMVC for business layer for my pet project.

Again by using ExtJS we can send data to server by form submits or as request parameters or in json format through Ajax requests. ExtJS uses JSON format in many situations to hold data. So I thought using JSON as data exchange format between EXTJS and Spring will be consistent.

The following code snippets explains how we can use ExtJS and SpringMVC3 to exchange data in JSON format.

1. Register MappingJacksonHttpMessageConverter in dispatcher-servlet.xml

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">

<property name="messageConverters">
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>

Don’t forget to copy jackson-json jar(s) to WEB-INF/lib

2. Trigger the POST request from ExtJS script as follows:

url : 'doSomething.htm',
method: 'POST',
headers: { 'Content-Type': 'application/json' },
params : { "test" : "testParam" },
jsonData: {
"username" : "admin",
"emailId" : ""
success: function (response) {
var jsonResp = Ext.util.JSON.decode(response.responseText);
Ext.Msg.alert("Info","UserName from Server : "+jsonResp.username);
failure: function (response) {
var jsonResp = Ext.util.JSON.decode(response.responseText);

3. Write a Spring Controller to handle the “/doSomething.htm” reguest.

public class DataController
@RequestMapping(value = "/doSomething", method = RequestMethod.POST)
public User handle(@RequestBody User user) throws IOException
System.out.println("Username From Client : "+user.getUsername());
System.out.println("EmailId from Client : "+user.getEmailId());
return user;

Any other better approaches?


  1. Using ExtJS, Spring and DWR. Have you tried that?

    For DWR you need a specific tree loader, and a DwrProxy. In ExtJS 4 the proxy can be quite simple, and also the tree loader uses it.

  2. I m facing issue with passing a nested java object to extjs. I have form panel that loads the fields, i m able to load name kind of field, but not able to load kind of fields into extjs. Could you tell me how to do it.

    Thank you.

  3. I am new to Maven + Jetty + Spring + Extjs. I am having running project of extjs. Now I want to write one jason file. For that I want ExtJs ajax call + java.

    I think your example can help me out. But I don't know how to do it?

    1) Copy and pasted the jackson-json jar(s)
    2) Wrote your code at my extjs file
    3) Where to write servlet? What is the procedure to write the srevlet? Means in which folder? Does we have to add this in any .xml file?

    Kind Regards,

Leave a Reply

Your email address will not be published. Required fields are marked *