Struts2 Access or add several properties (Request/session/application property)

Source: Internet
Author: User

7385055

STRUTS2 add request, session, application properties

The first method:
Actioncontext CTX = actioncontext.getcontext ();      Ctx.put ("R1", list); // Add a property      to the request Ctx.getsession (). Put ("S1", list); // adding attributes      to the session Ctx.getapplication (). Put ("A1", list); // adding attributes  to Application

HttpSession session =NULL; Session=servletactioncontext.getrequest (). GetSession (); if(Session.getattribute ("user")! =NULL) {Session.removeattribute ("User"); } session.setattribute ("User", user); Map<String,Object> session =NULL; Session=Actioncontext.getcontext (). GetSession (); if(Session.containskey ("User") {session.remove ("User"); } session.put ("User", user);
The second method:

Using the Servletrequestaware interface

 Public classLoginAction4extendsActionsupportImplementsServletrequestaware {PrivateHttpServletRequest request; PrivateHttpSession session; PrivateServletContext Application;  PublicString Execute () {Request.setattribute ("R1", "R1"); Session.setattribute ("S1", "S1"); Application.setattribute ("A1", "A1"); returnSUCCESS; } @Override Public voidsetservletrequest (HttpServletRequest request) { This. Request =request;  This. session =request.getsession ();  This. Application =Session.getservletcontext (); }        }  

Struts2 accessing the request, session, application properties

The first method:

Using struts tag:

<s:property value= "#request. R1"/>   <s:property value= "#session. S1"/> <s:property   value= "# Application.a1 "/>   

The second method:

Working with JSP objects

<%=request.getattribute ("R1")%> <br/>  <%=session.getattribute ("S1")%> <br/>  < %=application.getattribute ("A1")%> <br/>  

Struts2 Access or add several properties (Request/session/application property)

Related Article

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.