Using Servlet-api steps in Struts2

Source: Internet
Author: User

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

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.