Servletactioncontext Accessing the servlet API

Source: Internet
Author: User

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

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.