Use Servlet-api steps in Struts2:
To access the SERVLET-API in a decoupled manner:
Method One: Write your own code to get request, session, etc.
Objects such as request are declared in the 1.Action class:
Map<string,object> request;
2. Get Actioncontext instances:
Actioncontext Ac=actioncontext.getcontext ();
3. Get the Request object:
Request= (map<string,object>) ac.get ("request");
4. Accessing data in the map type:
Request.put ("loginaccess", "Your place of landing: Beijing");
Request.get ("loginaccess");
5. In the page to obtain the way to promote the preservation of data:
<s:property value= "#request. Loginaccess"/>
Method Two: Use the interface:
Control inversion (IoC) or Dependency injection (DI)
Dependency Injection reduces program coupling, improves cohesion, and facilitates portability, maintenance, expansion, and testing.
Simultaneous implementation of class 1.Action inheritance Actionsupport
Requestaware,sessionaware,applictionaware interface;
2 Add Override Method: Setrequest (), Setsession (), setappliction ();
3. Accessing data in the map type:
Request.put ("loginaccess", "Your place of landing: Beijing");
Request.get ("loginaccess");
Using Servlet-api steps in Struts2