My webapp is ready but I just wanted to add a little dropdown menu with the username as title. This is my jsp code:
In your servlet:
1) get your parameter:
String param = request.getParameter("param");
2) send it to the request object as an attribute:
request.setAttribute("param", param);
In your JSP:
use JSTL, and EL to return the attribute you sent from your servlet:
<input type="text" name="param" value="<c:out value="${param}" />" />
and there you go.
You can try an alternative:
<% request.getSession().getAttribute("name") %>
The reason that session
is not getting resolved is because you must have set session="false"
in your page directive.
Read this for further reference.
You can use EL, which is prefered in JSP.
<c:out value="${sessionScope.name}"/>
Or if the name
value is HTML safe, you can use
${sessionScope.name}
Make sure the JSP is allow access session.
<%@ page session="true" %>
To use core JSTL, make sure the following code is included.
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
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.