Home  >  Article  >  Java  >  What is servlet context

What is servlet context

清浅
清浅Original
2019-05-08 09:56:504425browse

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

 
   company 
    PHP中文网 

(2) Read

Read global initialization parameters through the methods provided by ServletContext

String company =  sctx.getInitParameter("company");

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!

Statement:
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
Previous article:What is the jsp script?Next article:What is the jsp script?