Home > Java > javaTutorial > body text

What is servlet context

清浅
Release: 2020-09-16 11:15:17
Original
4534 people have browsed it

The servlet context refers to the only object created for each web application that meets the requirements of the ServletContext interface after the container is started. Characteristics of servlet context: 1. A web application corresponds to a servlet context; 2. As long as the container is not closed, the servlet context will always exist.

What is servlet context

Servlet Context

After the container is started, a unique ServletContext interface requirement will be created for each web application. The object is generally called the Servlet context.

(Video tutorial recommendation: java course)

Servlet context characteristics

Uniqueness: one web application corresponds to one Servlet context.

Persistence: As long as the container is not closed and the application is not uninstalled, the Servlet context will always exist.

How to get the Servlet context

HttpSession, GenericServlet provides the getServletContext method to get the context

Note: GenericServlet is the parent class of HttpServlet

Example: Use Servlet context to read global initialization parameters

(1) Configure global initialization parameters

<context-param> 
   <param-name>company</param-name> 
    <param-value>PHP中文网</param-value> 
</context-param>
Copy after login

(2) Read

Read global initialization parameters through the methods provided by ServletContext

String company =  sctx.getInitParameter("company");
Copy after login

Related recommendations: java introductory tutorial

The above is the detailed content of What is servlet context. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!