如何将 EL 值分配给 java 中的变量
how to assign a EL value to a variable in java
我想将该对象 (${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;
}
您不能像在 jsp 小脚本中那样使用 ${}
。您必须手动获取它。你应该尝试这样的事情;
<%
List<Category> al = (List<Category>) request.getAttribute("categorys");
%>
或
<%
List<Category> al = (List<Category>) pageContext.getAttribute("categorys", pageContext.REQUEST_SCOPE);
%>
我想将该对象 (${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;
}
您不能像在 jsp 小脚本中那样使用 ${}
。您必须手动获取它。你应该尝试这样的事情;
<%
List<Category> al = (List<Category>) request.getAttribute("categorys");
%>
或
<%
List<Category> al = (List<Category>) pageContext.getAttribute("categorys", pageContext.REQUEST_SCOPE);
%>