(1) Servlet-related built-in objects: page and config
Page: Object type, which is rarely used.
The page object represents the JSP page itself, just like the this keyword in Java. More accurately, it represents the Servlet after JSP is translated. Therefore, it can call the method defined by the Servlet class.
Example:
<% @ Page contentType = "text/html; charset = UTF-8" %>
<% @ Page info = "test !!! "%>
<Html>
<Body>
<% = (HttpJspPage) page). getServletInfo () %>
<% -- Force type conversion is required because the page Object is of the Object type -- %>
</Body>
</Html>
Access the JSP page through a browser. The following output is displayed in the browser: test !!!
Config (master): ServletConfig
The cogfig object is an object of the ServletConfig interface and stores some Servlet initialization information. It is used to obtain the initialization parameters of JSP configuration and is valid only within the JSP page range. The common method is as follows:
Config. getInitParameter ("name"): Get the Servlet initialization parameter value with the specified name.
Config. getInitParameterNames (): gets the Servlet initialization parameter list and returns an enumeration instance.
Config. getServletContext (): Get the Servlet context (ServletContext ).
Config. getServletName (): get the name of the generated Servlet.
For example, in JSP, you can directly use the getInitParameter () method of the config object to obtain the local initialization parameters configured in JSP:
Configure the following in the jspPro2 web. xml file of the JSP project:
<Servlet>
<Servlet-name> myIndex </servlet-name>
<Jsp-file>/index. jsp </jsp-file>
<Init-param>
<Param-name> name </param-name>
<Param-value> zhangsan </param-value>
</Init-param>
</Servlet>
<Servlet-mapping>
<Servlet-name> myIndex </servlet-name>
<Url-pattern>/test </url-pattern>
</Servlet-mapping>
Configure the following in the index. JSP file of the jsp project:
<% @ Page language = "java" contentType = "text/html; charset = UTF-8" %>
<Html>
<Head>
<Title> config </title>
</Head>
<Body>
<%
String name = config. getInitParameter ("name ");
Out. print ("print information through the out object:" + name + "<br> ");
%>
Obtained initialization parameters: <% = name %>
</Body>
</Html>
Access www.2cto.com: http: // 172.16.0.71: 7070/jspPro2/test through a browser. The output is as follows:
Print information through the out object: zhangsan
The obtained initialization parameter is zhangsan.
From the column ynz1219