How to obtain parameters in struts2 JSP #, %, $

Source: Internet
Author: User

1. For example, to obtain the value of the username attribute stored in the session, you can use the following methods:
Session. getattribute ("username") gets the value of username,
Use the following method in El:
$ {Sessionscope. Username}

2. For example, we can use the following methods to obtain user request parameters:
Request. getparameter (string name)
Request. getparametervalues (string name)
In El, you can use PARAM and paramvalues to obtain data.
$ {Param. name}
$ {Paramvalues. name}

3. For example, to obtain a value named usercountry in a cookie, you can use $ {cookie. usercountry} to obtain it.

4. For example, initparam obtains the environment parameter set for the web site (context)
String userid = (string) application. getinitparameter ("userid ");
You can use $ {initparam. userid} to obtain the userid name.

5. pagecontext obtains details about other user requirements or pages.
$ {Pagecontext. Request. querystring} gets the request parameter string
$ {Pagecontext. Request. requesturl} retrieves the request URL, excluding the request parameter string
$ {Pagecontext. Request. contextpath} indicates the name of the Web application of the service.
$ {Pagecontext. Request. Method} Get the HTTP method (get, post)
$ {Pagecontext. Request. Protocol} gets the used protocol (HTTP/1.1, HTTP/1.0)
$ {Pagecontext. Request. remoteuser} obtains the user name
$ {Pagecontext. Request. remoteaddr} obtains the user's IP address
$ {Pagecontext. session. New} checks whether the session is new.
$ {Pagecontext. session. ID} obtains the session ID.
$ {Pagecontext. servletcontext. serverinfo} obtains the service information of the host.

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.