Java servlet and JSP accessing the same session bean

Posted by Mykola Golubyev on Stack Overflow See other posts from Stack Overflow or by Mykola Golubyev
Published on 2010-04-18T16:57:22Z Indexed on 2010/04/18 18:13 UTC
Read the original article Hit count: 417

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about java

Related posts about jsp