2017-10-09 11 views
0

에 변수에 EL 값을 할당

<% 

    ArrayList<Category> al =${categorys}; 

%>   

이 제어기

@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; 
} 

답변

1

jsp 스크립틀릿 에서처럼 ${}을 사용할 수 없습니다. 수동으로 가져와야합니다. 이런 식으로 시도해야합니다.

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

또는

<% 
List<Category> al = (List<Category>) pageContext.getAttribute("categorys", pageContext.REQUEST_SCOPE); 
%>