Fatih
Fatih

Reputation: 37

How do you dispay the current logged in user in JSP, Java servlets

Hi i would like to know how i can display the current users username/name on a webpage when they have logged on... i am storing their username like this

request.getSession().setAttribute("currentUser", username);

and wat to display their username on the jsp(web page) like this

<p> welcome <% request.getSession().getAttribute("currentUser"); %></p>

however it doesn't work... any tips? or a method that works

Upvotes: 1

Views: 8216

Answers (1)

lewthor
lewthor

Reputation: 434

Try using an expression, instead of a scriptlet:

<%= request.getSession().getAttribute("currentUser"); %>

Your scriplet will execute, but nothing is output. The result of an expression is automtically written to the output.

Upvotes: 3

Related Questions