0

In spring I have the url:--

http://localhost:8080/SpringMvc/viewdetail/id?key=1

I want to fetch the "key" value

So,I have done:--

    @RequestMapping(value = "/viewdetail/id",method=RequestMethod.GET, 
 params={"key"})

         public  @ResponseBody String viewDetail11(Map<String, Object> map,    
 HttpServletRequest request,
@RequestParam(value = "key") int key) throws IOException{

    detailservice.detail(key);

    return "viewdetail";
    }

But,with this code I am not getting any value.why?

2 Answers 2

1

With the same code in my local machine, the value of key is successfully retrieved. Can you please share your web.xml, Full controller class and spring version you are using?

Sign up to request clarification or add additional context in comments.

1 Comment

Yes..you were right..I had a problem in web.xml file
0

Try this, only slight modification:

@RequestMapping(value = "/viewdetail/id",method=RequestMethod.GET)

   public  @ResponseBody String viewDetail11(Map<String, Object> map,   
     HttpServletRequest request,  @RequestParam("key") int key) throws IOException {

        detailservice.detail(key);

        return "viewdetail";
    }

NOTE: If this doesn't work confirm the following:

  • param is appearing in url
  • no exceptions are being thrown (very important as it may not be binding properly)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.