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

假如想象 提交于 2021-02-10 19:43:04

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/26692480/how-do-you-dispay-the-current-logged-in-user-in-jsp-java-servlets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!