JSP gets the session and session emptying and judgment from the action

Source: Internet
Author: User

  This article mainly introduces JSP to get action from the session and session empty and judge, need friends can refer to the following

JSP gets the session value from the action there are several ways:    For example, I have a session in the action ("SessionID", "Sessionvalue")     I. Get with struts tag: <s:property value= "#session. SessionID"/>    II, <%=request.getsession.getattribute (" SessionID ");> session is also one of the built-in objects, you can use the session directly, more convenient than request.getsession   can also be written <%=session.getattribute (" SessionID ");>    III, El expressions get:${sessionscope.sessionid}    If the value is assigned to a bean, it is the same, similar to the ${ sessionscope.bean.beanproperty}    General Session time is 30 minutes if the session is judged to exist     code as follows: <%  String id = "";    String username = "";    User user = (User) session.getvalue ("Docuser");   //Judge U Whether the ser is empty, and if not NULL, the following. Otherwise, a null pointer exception is reported.   if (user!= null) {  id = user.getid ();    username = user.getusername (); } %>  &N Bsp You can also empty session  to get to the session and then set his value to null    code as follows: <%  lduser lduser = (lduser) Actioncontext.getcontext (). GetSession (). Get ("Lduser");    if (lDuser = = null) {  session.putvalue ("Lduser", null);  Out.println ("session to close"); %>   
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.