about what the value of Actioncontext.getcontext () is, and how struts2 gets the request,session,appliaction scope

Source: Internet
Author: User

I found a bug when I was doing struts today.

There is a tea object, which contains attributes such as Id,name, which I want to deposit into the request scope, as required by the project, which is said to be through Actioncontext.getcontext (). Put ("tea", tea); can achieve the effect of depositing the request scope.

But actually found that when I wrote this statement on the JSP page to get the Id:<s:property value= "#request. Tea.id" of tea in the Request field, the actual result is empty.

Why is that? After reviewing the multi-party data, we found that the actioncontext.getcontext () actually obtained the valuestack, rather than the request scope we imagined, so the above statement could not get the result we want.

Here's a way to get the valuestack,request,session,appliaction scope from struts2:

Package Com.hcj.action.database.admin;import Java.util.map;import Com.opensymphony.xwork2.actioncontext;import    Com.opensymphony.xwork2.actionsupport;public class Test extends Actionsupport {private Actioncontext context;    private MAP request;    Private MAP session; Private Map application;public Actioncontext GetContext () {return context;} public void SetContext (Actioncontext context) {This.context = context;} Public Map Getrequest () {return request;} public void Setrequest (Map request) {this.request = Request;} Public Map getsession () {return session;} public void Setsession (Map session) {this.session = session;} Public Map getapplication () {return application;} public void Setapplication (Map application) {this.application = Application;}        @Overridepublic String Execute () throws Exception {This.context = Actioncontext.getcontext ();        This.request = (MAP) this.context.get ("request");        This.session = This.context.getSession (); This.application = This.context.getApplication();        This.context.put ("Contenx", "I am Valuestack");        This.request.put ("Request", "I am Request");        This.session.put ("Session", "I am the Session");        This.application.put ("Application", "I am Application"); return SUCCESS;}}

about what the value of Actioncontext.getcontext () is, and how struts2 gets the request,session,appliaction scope

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.