Maja
Maja

Reputation: 59

Netbeans - storing username in the session bean?

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.

Upvotes: 0

Views: 712

Answers (1)

Sundararaj Govindasamy
Sundararaj Govindasamy

Reputation: 8495

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

You can find a full example here.

Upvotes: 1

Related Questions