Passing a List from Servlet to JSP

南笙酒味 提交于 2019-12-20 03:42:29

问题


When I try to set the value of a list in Servlet to a session variable and access it JSP like,

doGet

HttpSession session = request.getSession(true);
session.setAttribute("MySessionVariable", authorizeUserList);

JSP

<%List lst = session.getAttribute("MySessionVariable");%>

I get an error in JSP as "List cannot be resolved to a type"

So how should I do this? I want to pass a list from Servlet to JSP and populate a Drop down.


回答1:


Are you importing list and casting?

<%@page import="java.util.List"%>
<% List lst = (List) session.getAttribute("MySessionVariable"); %>



回答2:


You need to cast it to List as getAttribute return Object type.



来源:https://stackoverflow.com/questions/16982516/passing-a-list-from-servlet-to-jsp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!