DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Streamlining Your Workflow With the Jenkins HTTP Request Plugin: A Guide to Replacing CURL in Scripts
  • How To Create a Stub in 5 Minutes
  • Streamlining Event Data in Event-Driven Ansible
  • Deploying a Scala Play Application to Heroku: A Step-by-Step Guide

Trending

  • Scaling Mobile App Performance: How We Cut Screen Load Time From 8s to 2s
  • Failure Handling Mechanisms in Microservices and Their Importance
  • My LLM Journey as a Software Engineer Exploring a New Domain
  • Solid Testing Strategies for Salesforce Releases
  1. DZone
  2. Coding
  3. Languages
  4. How to POST and GET JSON between EXTJS and SpringMVC3

How to POST and GET JSON between EXTJS and SpringMVC3

By 
Siva Prasad Reddy Katamreddy user avatar
Siva Prasad Reddy Katamreddy
·
Jun. 29, 11 · Interview
Likes (0)
Comment
Save
Tweet
Share
55.4K Views

Join the DZone community and get the full member experience.

Join For Free

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

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 would be consistent.


The following code snippets explain 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">
       <list>
          <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
       </list>
  </property>        
</bean>
   
Add jackson-json jar(s) to WEB-INF/lib
    
2. Trigger the POST request from ExtJS script as follows:
   
  
Ext.Ajax.request({
  url : 'doSomething.htm',
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },                        
  params : { "test" : "testParam" },
  jsonData: {
                   "username" : "admin",
                    "emailId" : "admin@sivalabs.com"
                 },
  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);
                  Ext.Msg.alert("Error",jsonResp.error);
            }
});
    
3. Write a Spring Controller to handle the "/doSomething.htm" reguest.

@Controller
public class DataController
{
    @RequestMapping(value = "/doSomething", method = RequestMethod.POST)
    @ResponseBody
    public User handle(@RequestBody User user) throws IOException
    {
        System.out.println("Username From Client : "+user.getUsername());
        System.out.println("EmailId from Client : "+user.getEmailId());
        user.setUsername("SivaPrasadReddy");
        user.setEmailId("siva@sivalabs.com");        
        return user;
    }
}

Any other better approaches?

From http://sivalabs.blogspot.com/2011/06/how-to-post-and-get-json-between-extjs.html
JSON POST (HTTP)

Opinions expressed by DZone contributors are their own.

Related

  • Streamlining Your Workflow With the Jenkins HTTP Request Plugin: A Guide to Replacing CURL in Scripts
  • How To Create a Stub in 5 Minutes
  • Streamlining Event Data in Event-Driven Ansible
  • Deploying a Scala Play Application to Heroku: A Step-by-Step Guide

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!