File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring controllers and ajax

 
Jason Nesbitt
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to have a Spring controller return JSON formatted data instead of a physical view (jsp file)? All of the interfaces I have seen require you to return a ModelAndView. I could achieve what I want to by using plain servlets but I'd like to take advantage of Spring's IOC features.

Thank you

Jason
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the example code snippet using json-simple.jar,



Cheers.
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can return just a String, you can return null, you can return a View technology object like say JstlView, and also you can just return an object that is the Model, it doesn't always have to be a ModelAndView object.

Mark
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, and Spring also has Spring JavaScript to help with Ajax.

Mark
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mark Spritzler:
....and also you can just return an object that is the Model, it doesn't always have to be a ModelAndView object.


Actually, I am having Object here. Changed to match the question.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mark Spritzler:
Oh, and Spring also has Spring JavaScript to help with Ajax.


Yeah, came across this but haven't tried it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic