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

  • SEARCH
  • Home
  • 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 7692087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:46:19+00:00 2026-05-31T20:46:19+00:00

My controller is like this @RequestMapping(value =/getTaggedProducts, method = RequestMethod.GET) @ResponseBody public String getProductsTagged(@RequestParam(questionnaireId)Long

  • 0

My controller is like this

@RequestMapping(value ="/getTaggedProducts", method = RequestMethod.GET)
@ResponseBody
public String getProductsTagged(@RequestParam("questionnaireId")Long questionnaireId){
    Map<String, Object> response = new HashMap<String, Object>();
    try{
        Questionnaire questionnaireProduct = Questionnaire.findQuestionnaire(questionnaireId);
        Organisation userOrg = getUserAffiliation();

        if (questionnaireProduct == null) throw new QuestionnaireBuilderException("Questionnaire '" + questionnaireId + "'does not exist");
        if (!questionnaireProduct.isEditable()) throw new QuestionnaireBuilderException("You cannot edit a questionnaire which has been assigned");

        Set<Product> productCategories = questionnaireProduct.getProducts();
        List<Long> productIds = new ArrayList<Long>();
        for(Product p: productCategories){
            productIds.add(p.getId());
        }

        LOG.debug("Product Categories successfully added to questionnaire");
        response.put("message", "success");
        response.put("products", productIds);
    } catch (QuestionnaireBuilderException e) {
        LOG.debug(e.getMessage(), e);
        response.put("message", e.getMessage());
    } catch (Exception e) {
        LOG.error("Unhandled Exception: " + e.getMessage(), e);
        response.put("message", "Unhandled Exception");
    }
    return new JSONSerializer().exclude("*.class").deepSerialize(response);
}

Will not setting a response header pose any problems. I know how to set the response header from this question – In Spring MVC, how can I set the mime type header when using @ResponseBody
In my ajax call I specify

datatype: "json"

Is this sufficient or I need to set the header too. Thanks

  • 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-05-31T20:46:21+00:00Added an answer on May 31, 2026 at 8:46 pm

    Since you’re manually generating the JSON response as a string, yes you do need to add the header yourself.
    You can do this by adding an HttpServletResponse argument to the handler method and calling addHeader(…).

    Alternatively (and better I think) is using Spring to help with JSON serialisation automatically. Try adding Jackson to the classpath and instead of returning a string, return your structure. e.g.:

    @RequestMapping(value="/getTaggedProducts",method=RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> getProductsTagged(@RequestParam("questionnaireId") Long questionnaireId) {
        final Map<String,Object> json = ...;
        return json;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method in my controller like this: @RequestMapping(value=getData, method=RequestMethod.GET) @ResponseBody public List<MyDataObj>
Imagine a code like this one: @RequestMapping(value=/users, method=RequestMethod.GET) public String list(Model model) { ...
this is from my controller.. @RequestMapping(value = /add, method = RequestMethod.GET) public String add(Model
@RequestMapping(value = /testerror, method = RequestMethod.GET) public @ResponseBody ErrorTO testerror(HttpServletRequest request, HttpServletResponse response) {
in spring 3 controller @RequestMapping(value = /employee/{id}, RequestMethod.GET) public @ResponseBody Employee getEmployee(@PathVariable long empID)
code is like this: @Controller public class TestController { @RequestMapping(value = /testerror, method =
I have a simple Controller that looks like this:- @Controller @RequestMapping(value = /groups) public
I've defined this method in my Spring MVC Controller : @RequestMapping(value = {id}/content, method=RequestMethod.POST)
I have a method in my Controller which looks like this: @RequestMapping(value = /test,
I'm using Spring MVC and jquery autocomplete, my spring controller looks like this @RequestMapping(value

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.