Accessing the servlet API using Servletactioncontext
The action accesses the Servlet API and accesses the Servlet API through Ruquest, session, and Applicplition.
The SERVLETAPI that the city needs to visit in Web applications are HttpServletRequest, HttpSession, and ServletContext
These three interfaces represent the request, session, application of the built-in objects in the JSP, respectively.
Struts 2 provides a actioncontent class that can be accessed by the action of Struts 2 through this class Servletapi
in order to have direct access to the Servlet Api,struts 2 also provides a Servletaction tool class that contains the following static methods
|
return value |
|
function description |
|
httpservletrequest |
getrequest () |
get HttpServletRequest objects for Web Apps |
|
httpservletresponse |
getresponse () |
get HttpServletResponse objects for Web Apps |
|
servletcontext |
getservletcontext () |
get ServletContext object for web App |
|
PageContext |
Getservletcontext () |
Get the ServletContext object for your web App |
With the help of the Servletactioncontext tool class, action can access the servlet API in a much simpler way.
public class Baaction extends Actionsupport implements Sessionaware,requestaware {@Overridepublic void setsession ( Map<string, object> session) {this.session = Session;httprequest = Servletactioncontext.getrequest (); context = Httprequest.getsession (). Getservletcontext (); response = Servletactioncontext.getresponse ();}}
Servletactioncontext Accessing the servlet API