JSP built-in object -- Application

Source: Internet
Author: User

The application object represents the web application, so the application is used to operate web application-related data. The Application Object usually has the following two functions:

1. Data is shared among servlets across multiple JSP pages of the entire web application.

The application uses the setattribute (string attrname, object Value) method to set a value to the attrname attribute of the application. The value of this attribute is valid for the entire web application, therefore, each JSP page or servlet of the Web application can access this attribute by getattribute (string attrname ).

Website traffic statistics: application. setattribute ("count", String. valueof (I ++ ));

Note: on different pages, you can use application. getattribute ("count") to obtain the value of the count attribute. The attributes of the application are shared with the JSP of the entire web application.

No application built-in objects exist in the servlet. Each web application has only one servletcontext instance. On the JSP page, you can access the instance through the Application built-in object, while the servlet must obtain the instance through code.

2. Access the configuration parameters of the Web application.

You can use application. getinitparameter (string paramname) to obtain the configuration parameter. You must first configure the parameter in the context-Param element in the web. xml file.

<! -- Configure the first parameter -->

<Context-param>

<Param-Name> name1 </param-Name>

<Param-value> value1 </param-value>

`

`

`

`

`

</Context-param>

In this way, some configuration information can be configured in the web. xml file, avoiding the use of hard encoding in the Code, thus improving program portability.

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.