Java servlet and JSP accessing the same session bean
- by Mykola Golubyev
Let's say I have simple Login servlet that checks the passed name and creates User object and stores it in a session.
User user = new User();
user.setId(name);
request.getSession().setAttribute("user", user);
response.sendRedirect("index.jsp");
In the index.jsp page I access the user object through jsp:useBean
<jsp:useBean id="user" scope="session"
class="package.name.User"/>
<div class="panel">
Welcome ${user.id}
</div>
It works so far.
The question: is this a valid usage or it is just current implementation uses the same name as the jsp bean id when stores and looks for a bean in a session?