My webapp is ready but I just wanted to add a little dropdown menu with the username as title. This is my jsp code:
<i class="icon-user"></i>
<%
session.getAttribute("name");
%>
<span class="caret"></span>
and it sais
session cannot be resolved
9: <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
10: <i class="icon-user"></i>
11: <%
12: session.getAttribute("name");
13: %>
14: <span class="caret"></span>
15: </a>
There is a session because I'm logged in.
Kind regards,
I agree with answer given by @Pau Kiat Wee. But you can also set this user name from the controller in modelmap and then just simple use it in a EL. That would also be a good option. Hope this helps you. Cheers.
In your servlet:
In your JSP:
and there you go.
You can try an alternative:
The reason that
session
is not getting resolved is because you must have setsession="false"
in your page directive.Read this for further reference.
You can use EL, which is prefered in JSP.
Or if the
name
value is HTML safe, you can useMake sure the JSP is allow access session.
To use core JSTL, make sure the following code is included.