The first method:
Actioncontext CTX = Actioncontext.getcontext (); Ctx.put ("R1", list);//Add Attribute ctx.getsession () to request. Put ("S1", list);//Add attributes to session
HttpSession session =null; Session = Servletactioncontext.getrequest (). getsession (); if (Session.getattribute ("user") = null) { session.removeattribute ("user"); } Session.setattribute ("user", user); map<string,object> session = NULL; Session = Actioncontext.getcontext (). getsession (); if (Session.containskey ("user")) { session.remove ("user"); } Session.put ("user", user);
The second method:
Using the Servletrequestaware interface
public class LoginAction4 extends Actionsupport implements Servletrequestaware { private httpservletrequest request ; Private HttpSession session; Private ServletContext Application; Public String Execute () { request.setattribute ("R1", "R1"); Session.setattribute ("S1", "S1"); Application.setattribute ("A1", "A1"); return SUCCESS; } @Override public void Setservletrequest (HttpServletRequest request) { this.request = Request; This.session = Request.getsession (); This.application = Session.getservletcontext (); } }
Struts2 accessing the request, session, application properties
The first method:
Using struts tag:
<s:property value= "#request. R1"/> <s:property value= "#session. S1"/> <s:property value= "# Application.a1 "/>
The second method:
Working with JSP objects
<%=request.getattribute ("R1")%> <br/> <%=session.getattribute ("S1")%> <br/> < %=application.getattribute ("A1")%> <br/>
Struts2 accessing or adding Request/session/application properties