" /> " /> "/>

Netbeans - storing username in the session bean?

668 views Asked by At

I am currently trying to pass the username to a servlet in netbeans. The username is input in the login, such that

<input type="text" name="username">

I then access this username in servletA by

String username = request.getParameter("username");

After that a user is taken to a welcome page which has a button which activates servletB, that I want to pass the username parameter to. When I try accessing it by username is doesn't work because that value is only on the login page.

I read that in theory it can be done by storing the username in the SessionBean, but I am not sure how to do that. I would appreciate any advice.

1

There are 1 answers

1
Sundararaj Govindasamy On
    HttpSession session = request.getSession();
    String username = request.getParameter("username");
    session.setAttribute("userName", username);

You can find a full example here.