0

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.

Maja
  • 59
  • 1
  • 11

1 Answers1

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

You can find a full example here.

Sundararaj Govindasamy
  • 8,180
  • 5
  • 44
  • 77
  • Hi Sundararaj, Thank you for your help, that's what I have done in servletA `HttpSession session = request.getSession(); String username = request.getParameter("username"); session.setAttribute("username", username);` but because username doesn't in the webpage that requests servletB i get an error when trying to do the same. – Maja Apr 03 '17 at 19:05