Xi. Common APIs for ServletContext classes:
1.getContext (String Uripath): Returns the ServletContext object represented by Uripath in the server
2.getInitParameter (String name): Returns the value of the name parameter in the ServletConfig object
3.getMineType (String file): Returns the MIME type of the file represented by the files parameter
4.getRequestDispatcher (String Path): Returns the Requestdispacher object represented by path
5.getResourceAsStream (String Path): Returns the resource corresponding to the path as an input stream, in which the object can be any form of data, and the path parameter must start with "/" and relative to the context Root
12. How to use Servletcontxt to read and save property files:
1. Create Java.util.Properties class objects
2. Get ServletContext Object
3. Read the property file into an input stream object as an input stream
4. Load an input stream object into a Properties object
5. Save the Properties object to the ServletContext object
13. How to load static text when a Web application starts:
1. Create a subclass that inherits the HttpServlet class and set the Load-on-startup property when this servlet is configured in Web.xml:
SomeClass
Somepackage. SomeClass1
2. Create the Java.util.Properties class in the Init () method of this servlet
3. Get the ServletContext object for the current Web application
4. Read the property files in the Web-inf directory into the input stream InputStream:
InputStream in = context.getresourceasstring ("web-inf/someproperties.properties");
5. Load an input stream into a Property object
Ps.load (in);
6. Save the Property object to the top
Context.setattribute ("AttributeName", PS);
14. How to create a label processing class:
1. Introduction of necessary resources:
Import javax.servlet.jsp.*;
Import javax.servlet.http.*;
Import java.util.*;
Import java.io.*;
2. Inherit the TagSupport class and overwrite the doStartTag ()/doendtag () method
3. Get the Java.util.Properties object from the ServletContext object
4. Get the property value of the key from the Properties object
5. Processing the acquired attributes and outputting the results
Create Tag library description file (Tag descriptor):
1. Tag library description file, referred to as TLD, using XML file format, defines the user's tag library. Elements in a TLD file can be grouped into 3 categories:
A.: Tag Library elements
B.: Label elements
C.: Label Property elements
2. The tag library element is used to set the relevant information of the tag library, and its common properties are:
A.shortname: Specifies the tag library default prefix name (prefix)
B.uri: Set Tag Library's unique access notation
3. The label element is used to define a label, and its common properties are:
A.name: Set Tag's name
B.tagclass: Set tag's processing class
C.bodycontent: Set the subject (body) content of the label
1). Empty: Indicates that there is no body in the label
2). JSP: Indicates that the body of the tag can be added to the JSP program code
3). Tagdependent: Indicates that the contents of the label are handled by the label itself
4. Tag property elements are used to define the properties of a label, and its common properties are:
A.name: Property Name
B.required: property is required, default is False
C.rtexprvalue: Whether the property value can be an request-time expression, that is, an expression similar to <%=...% >
16, use the label in the Web application:
1. If a custom JSP tag is used in a Web application, you must include an element in the Web.xml file that declares the tag library where the referenced label is located
/sometaglib
/web-inf/sometld.tld
2.: Set tag Library's unique identifier, in the Web application will be based on it to reference tag Libray
3.: Specify the location of the TLD file corresponding to the tag library
4. In the JSP file you need to add the <% @ taglib% > directive to declare a reference to the tag library. For example:
<% @ taglib prefix = “somePrefix” uri = "/someuri" %>
5.prefix represents the prefix for referencing the label of this tag library in a JSP Web page, which is used to specify the identifier of the tag library and must be consistent with the attributes in the Web.xml.