jsp gets session and session from action to clear and judge

  • 2020-08-22 22:37:25
  • OfStack

There are 1 methods for jsp to obtain the session value problem from action:

So I have an session in action ("sessionid","sessionValue")

1. Obtain with struts tag: < s:property value="#session.sessionid"/ >

2. < %=request.getSession.getAttribute("sessionid"); > session is also one of the built-in objects. You can use session directly, which is much more convenient than ES23en.getSession
We can also write it as < %=session.getAttribute("sessionid"); >

3. el expression: ${sessionScope. sessionid}

If the value is bean, it will look like ${sessionScope.bean.beanProperty}

General session time is 30 minutes if session exists
 
<% 
String id = ""; 

String username = ""; 

User user = (User)session.getValue("docUser"); 

// judge user Is null, if not, operate the following. Otherwise, null pointer exception will be reported.  
if(user != null){ 
id = user.getId(); 

username = user.getUsername(); 
} 
%> 

You can also empty session
Get session and set its value to null
 
<% 
Lduser lduser = (Lduser) ActionContext.getContext().getSession().get("lduser"); 

if (lduser == null) { 
session.putValue("lduser",null); 
out.println("session To shut down "); 
%> 

Related articles: