Struct2 Access or add request/session/application

Source: Internet
Author: User

Access or add Request/session/application
1 by Actioncontext
This place
Public String Execute ()
{
Actioncontext CTX = Actioncontext.getcontext ();
Ctx.getapplication (). Put ("app", "lll");
Ctx.getsession (). put ("SES", "session Range");
Ctx.put ("req", "request Scope");
Return "Success";
}
Take it out.

${applicationscope.app}

${sessionscope.ses}

${requestscope.req}




2 getting the corresponding object

2.1 Direct access through the Servletactioncontext class:
Public String RSA () throws exception{
HttpServletRequest request = Serletactioncontext.getrequest ();
Request.setattribute ("req", "Request range attribute");
Request.getsession (). SetAttribute ("res", "Session Properties");
}

2.2 Implementation of the specified interface, injected by the STRUCT2 framework runtime
public class Helloworldaction implements Servletrequestaware,servletresponseaware,servletcontextaware
{
private HttpServletRequest request;
public void Setservletrequest (HttpServletRequest req) {
This.request = res;
}
}

Struct2 Access or add request/session/application

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.