Required String parameter is not present Spring MVC

65,328

Solution 1

Add required=false attribute to @RequestParam..Change to

@RequestParam(required=false,name="views") String view,..

Solution 2

Add required=false to the @RequestParam notation for both. Or you could decide to explicitly use one, set it to required=false and set the other as the defaultValue.

See the documentation for further information.

Share:
65,328
LeTadas
Author by

LeTadas

Updated on July 21, 2021

Comments

  • LeTadas
    LeTadas almost 3 years

    I want to access two different pages in my browser using:

    http://localhost:8080/name?views
    

    and

    http://localhost:8080/name?uviews
    

    But I'm getting error Required String parameter 'uviews' is not present when I use first url and I get Required String parameter 'views' is not present when I use second one.

    here is my Response body

    @ResponseBody     
    public Object getViewInJson(@RequestParam("views") String views ,@RequestParam("uviews") String uviews) throws IOException{
    
     loader = new AnalyticsLoader();
    
    
    
        return loader.AnalyticsLoader(views,uviews);
    }
    

    How can access both views and uviews?

  • Ajay Kumar
    Ajay Kumar over 4 years
    Oh my god.! I do not have words to say thanks. Kept browsing through everywhere for this. Thanks a ton. Wish I could give million up-votes.
  • saurabh gupta
    saurabh gupta over 3 years
    @AjayKumar I feel you bro!