Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8789585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:26:58+00:00 2026-06-13T22:26:58+00:00

I am having a question that how can I send JSON Object from Springs

  • 0

I am having a question that how can I send JSON Object from Springs MVC so that I can convert it into a JavaScript Object on my HTML Page.

In a traditional way I do it: Below is a snippet from Java Servlet which sets a request attribute and forward it to the JSP Page.

   JSONObject jsonObj = new JSONObject();
   jsonObj.put("name","test");
   jsonObj.put("age",24);
   request.setAttribute("jsonObj",jsonObj);
   request.getRequestDispatcher("test.jsp").forward(request,response);

In JSP I retrieve as :

   <script type="text/javascript">
    var jsonObj =<%=request.getAttribute("jsonObj"); %>;
    alert("name = "+jsonObj.name+" ; age = "+jsonObj.age); // This will output name and age from the JSON Object
   </script>

So what I need to ask how can I do the same in Springs MVC. How can I send the JSONObject from Dispatcher Servlet, and convert it to JS object in my JSP page ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:26:59+00:00Added an answer on June 13, 2026 at 10:26 pm

    An easy way to do this using the ObjectMapper. It will create an JSON String from your Object. And that you can send to your view/jsp.

    I put an small example of a controller I do this (just snipped).

    @Controller
    public class UsersSettingsController {
    
        @Autowired
        UserSettingsDefaultService userSettingsService;
    
    
        @RequestMapping(value="/userSettings/dynamic/userSettings", method=RequestMethod.GET)
        public ModelAndView get() throws Exception {
            ModelAndView mav = new ModelAndView();
            ObjectMapper mapper = new ObjectMapper();
    
    
        User user = (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        UserSettings userSet = userSettingsService.getUserSettingsByUser(user);
    
        mav.addObject("userSettingsJSON", mapper.writeValueAsString(userSet));
    
        mav.setViewName("userSettings/dynamic/filter");
    
    
            return mav;
        }
    }
    

    Or course can you create your JSON Object in your Contoller step by step like you did in your example. Then you don’t need the Mapper, just sending the String to your View.

    In the JSP you load the json String like this into a JS var:

    var jsonString = '${userSettingsJSON}';
    

    To get elements from JSON String or parse, see: http://www.json.org/js.html.
    I’m an KnockOut Framework Fan would do it with it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble with a homework question that I've been working at for
I have a seemly simple question with SQL that I am having trouble figuring
Veterans please forgive me for asking silly question. I understand that a class having
I am just getting into Sharepoint, and I have a question about having a
Question: I'm having a little trouble with jQuery: Consider this HTML, where I want
I am having a problem very similar to this question here: Can I use
Having watched samples from Rob Conery's Kona application, I see that he is using
my question is the following How can I display a standard rss page after
EDIT: This question can be summed up as follows: How can two separate html
I have the same question that was asked in another post except I'm having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.