0

Here is my code-

@controller
public ModelAndView ServiceContract(HttpServletRequest httpServletRequest,
            HttpServletResponse httpServletResponse) {      
        int sortId = Integer.parseInt(httpServletRequest.getParameter("sortId"));
                ModelMap map = new ModelMap();
        map.addAttribute("jsonString",jsonStringX); 
        return new ModelAndView(jsonView,map);
    }

inside my jsp file where from we are caaling this controller method.-

var sortId= [1,2, 3, 4 , 5];

how to obtain the values of it in controller?

1

1 Answer 1

0
String sortId = httpServletRequest.getParameter("sortId");
int sortIds[] = null;
if(sortId !=null){
       String array[] = sortId.split(",");
       sortIds = new int[array.length];
       for(int i=0;i<array.length;i++){
           try{
            sortIds[i] = Integer.parseInt(array[i]); 
           }catch(Exception e){
           }
       }
}

Now sortIds array have these values [1,2, 3, 4 , 5]

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

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.