How to use session in JSP pages to get information?

前端 未结 7 2254
北恋
北恋 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:32

    JSP implicit objects likes session, request etc. are not available inside JSP declaration <%! %> tags.

    You could use it directly in your expression as

    Username: 
    " />
    

    On other note, using scriptlets in JSP has been long deprecated. Use of EL (expression language) and JSTL tags is highly recommended. For example, here you could use EL as

    Username: 
    
    

    The best part is that scope resolution is done automatically. So, here username could come from page, or request, or session, or application scopes in that order. If for a particular instance you need to override this because of a name collision you can explicitly specify the scope as

     or,
     or,
    
    

提交回复
热议问题