0

i want to assign that object(${categorys}) to ArrayList

this is the jsp

<%

     ArrayList<Category> al =${categorys};

 %>        

This is the controller

@RequestMapping(value = "/cat", method = RequestMethod.GET)
public ModelAndView getTrancationHistory() {

    ArrayList<Category> allData = service.viewAllCategory();
    //handle your code here...
    System.out.println(allData);
  for (Category allData1 : allData) {
        System.out.println(allData1.getCategoryName());
    }


    ModelAndView modelAndView = new ModelAndView();
    modelAndView.setViewName("WEB-INF/views/cat");
    modelAndView.addObject("categorys", allData);
    return modelAndView;
}
Suhad Mendis
  • 51
  • 1
  • 11

1 Answers1

2

You cannot use ${} like that in a jsp scriptlet. You have to manually fetch it. You should try something like this;

<%
List<Category> al = (List<Category>) request.getAttribute("categorys");
%>

or

<%
List<Category> al = (List<Category>) pageContext.getAttribute("categorys", pageContext.REQUEST_SCOPE);
%>
Nico Van Belle
  • 4,911
  • 4
  • 32
  • 49