2

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.

Prasanna
  • 2,593
  • 7
  • 39
  • 53
  • [Scriptlets are since a decade discouraged](http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files/). I recommend to learn taglibs/EL before it's too late. This way you also don't need those `import` statements anymore. – BalusC Jun 07 '13 at 11:05

2 Answers2

3

Are you importing list and casting?

<%@page import="java.util.List"%>
<% List lst = (List) session.getAttribute("MySessionVariable"); %>
shyam
  • 9,134
  • 4
  • 29
  • 44
0

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

Harish Kumar
  • 528
  • 2
  • 15