如何在java中为变量分配EL值

如何在java中为变量分配EL值,java,spring,jsp,spring-mvc,el,Java,Spring,Jsp,Spring Mvc,El,我想将该对象(${categorys})分配给ArrayList 这是jsp <% ArrayList<Category> al =${categorys}; %> 这是控制器 @RequestMapping(value = "/cat", method = RequestMethod.GET) public ModelAndView getTrancationHistory() { ArrayList<Categor

我想将该对象(${categorys})分配给ArrayList

这是jsp

<%

     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;
}
@RequestMapping(value=“/cat”,method=RequestMethod.GET)
公共模型和视图getTrancationHistory(){
ArrayList allData=service.viewAllCategory();
//在这里处理你的代码。。。
System.out.println(所有数据);
对于(类别allData1:allData){
System.out.println(allData1.getCategoryName());
}
ModelAndView ModelAndView=新建ModelAndView();
setViewName(“WEB-INF/views/cat”);
添加对象(“类别”,所有数据);
返回模型和视图;
}

您不能像在jsp脚本中那样使用
${}
。您必须手动获取它。你应该试试这样的东西

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


您不能像在jsp脚本中那样使用
${}
。您必须手动获取它。你应该试试这样的东西

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