GET request and session in action, application (4)

Source: Internet
Author: User

Obtain the request, session, and application information in the background, and add information to it before reading the page. The implementation methods include: 1. Declare various types in action, this method is obtained using actionContext, and the values obtained in actionContext are of the Map type. [Java] package com. thridProject. action; import java. util. map; import com. opensymphony. xwork2.ActionContext; import com. opensymphony. xwork2.ActionSupport; public class WebProperty extends ActionSupport {private Map request; private Map session; private Map application; public WebProperty () {request = (Map) ActionContext. getContext (). get ("request"); session = (Map) ActionContext. getContext (). getSessio N (); application = (Map) ActionContext. getContext (). getApplication ();} public String execute () {request. put ("a", 1); session. put ("B", 2); application. put ("c", 4); return SUCCESS;} 2. The second method is to implement the interface provided by struts, for example, code: [java] package com. thridProject. action; import java. util. map; import org. apache. struts2.interceptor. applicationAware; import org. apache. struts2.interceptor. requestAware; import org. apache. Struts2.interceptor. sessionAware; import com. opensymphony. xwork2.ActionSupport; public class WebProperty extends ActionSupport implements RequestAware, SessionAware, ApplicationAware {/*** author Zhang chunlei */private static final long serialVersionUID =-callback; private Map <String, object> request; private Map <String, Object> session; private Map <String, Object> application; public void setRe Quest (Map <String, Object> request) {this. request = request;} public void setSession (Map <String, Object> session) {this. session = session;} public void setApplication (Map <String, Object> application) {this. application = application;} public String execute () {request. put ("a", 1); session. put ("B", 2); application. put ("c", 4); return SUCCESS ;}second is the most common method. 3. The third method is to use import org. apache. struts2.ServletActionContext to get the request. You can view [java] request = ServletActionContext. getRequest (); 4. Implement the ServletRequestAware interface and use dependency injection. The values of the first two types are Map values, and the actual values of the last two types are obtained.

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.