aspose file tools*
The moose likes Other Application Frameworks and the fly likes Spring controllers and ajax Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Spring controllers and ajax" Watch "Spring controllers and ajax" New topic
Author

Spring controllers and ajax

Jason Nesbitt
Greenhorn

Joined: Aug 16, 2004
Posts: 16
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

Joined: Aug 15, 2004
Posts: 2874
Here is the example code snippet using json-simple.jar,



Cheers.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

Oh, and Spring also has Spring JavaScript to help with Ajax.

Mark
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Aug 15, 2004
Posts: 2874
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring controllers and ajax