Action accesses the Servlet API_, the main access is as follows:
1.>Get request object
2.>Get request parameters
3.> Get the response object, which can be used to pass cookies
3.> Get scope objects, request, Session, application, and set shared data,
Access method 1:
By implementing the setter method in the perceptual interface, the request parameter in the setter method is passed to this class:
That is, define a member variable in this class to receive the request in the setter method.
If you also need to obtain response, Session, application and other objects, then you only need to implement ServletResponseAware at the same time.
ApplicationAware, SessionAware interface, and implement the setter method, as shown in the figure:
Access method 2: ServletActionContext tool class through struts
The corresponding request and response objects are obtained through the static method in this class.
Method 3: Pass the ActionContext tool class
This class is the parent class of ServletAcitonContext, which represents the context object of Action and indicates the existence of Action environment
Create this class object through the getContext() method in this class, and then get the corresponding object by calling the class method. If you use the getParameters() method, it will return
A map of an array of attribute names and attribute values for a parameter. When you need to set the request parameters, you will add a key-value pair to the obtained map (that is, use the Map.put(key, value) method;),
The encapsulation setting of shared request data can be completed.
Similarly, for Session and application, first use getSeesion() and getApplication(), this method also returns a Map collection. Similarly, when sharing parameters need to be set,
Then, by adding key-value pairs to the obtained Map (that is, using the Map.put(key, value) method;), the encapsulation setting of shared data can be completed. As shown in the figure,
The above simple example of the Action accessing the Servlet API is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.