How to use session in JSP pages to get information?

前端 未结 7 2291
北恋
北恋 2020-11-27 03:14

I have a JSP page used for editing some user\'s info. When a user logins to the website, I keep the information in the session, then in my edit page I try the following:

7条回答
  •  庸人自扰
    2020-11-27 03:37

    Use

    <% String username = (String)request.getSession().getAttribute(...); %>
    

    Note that your use of <%! ... %> is translated to class-level, but request is only available in the service() method of the translated servlet.

    See how JSP code is translated to a servlet.

提交回复
热议问题