Java Server Pages, the server-side technology responsible for page display, can nest Java language to replace the way of using Servlet to generate pages, The bottom layer is converted into Servlet .
The resource can be uniquely determined by itself The path starts with the protocol, such as http in an HTTP request.
You must rely on other paths to uniquely determine the path of the resource, and the content does not start with a protocol.
Access path + resource name, the resource name is the content after the last "/", and the rest is access path.
Resources placed in the WEB-INF directory can only be forwarded through programs Visit , which cannot be accessed directly through the browser and is relatively safe. When the redirect is executed, the address is sent to the browser, and the browser makes the request. Therefore, the redirect within the program cannot directly access the resources in the WEB-INF directory.
In the resources under the WEB-INF directory, only the path relative to the server can be used, and the path relative to the current resource access path cannot be used, that is, the following path form can only be used:
${pageContext.request.contextPath}/xxx
All redirections can only be in the form of paths relative to the server, because redirection can To access resources in other projects, the starting point of the path is the server. According to the change of the address in the address bar, all requests in HTML pages and JSP pages can be regarded as redirects, and all paths must be in a form relative to the server.
All forwarding can only be in the form of a path relative to the project, because forwarding can only access files within the same project resource.
is used to set information that is valid in the entire JSP page. The syntax format of the command tag is:
<%@ tagName attr="value"...%>
There are three instruction identifiers in JSP:
The main attributes used are:
contentType: Set the MIME type and encoding method of the page.
isErrorPage: Set the page as an error handling page. It is usually used in combination with the built-in object exception to handle the error information of another page.
errorPage: Specify the error handling page for the page. When an error occurs when the page is running, jump to the specified page.
<%@ include file="path"%>
Static inclusion, used to include a JSP page in the current page. The so-called static inclusion means that the included JSP page is presented as it is in the containing page, and the same Servlet is generated as the containing page.
<%@ taglib prefix="c"uri=""%>
is used to introduce the tag library to the current page and use the specified prefix to reference the tag library tags in .
There are 3 action identifiers in JSP:
Dynamic inclusion is used to include a JSP page in the current page. The so-called dynamic inclusion means that the included page is compiled and presented in the current page. The including page and the included page each generate a Servlet.
<jsp:forward page="url"/>
is used for page jump.
<jsp:param name="paramName"value="paramValue>
Used in conjunction with the
request: used to obtain request information, such as request parameters and client information .
# response: used to respond to client requests.
# out: used to output response information.
session: Represents a session between the browser and the server. The HTTP protocol is a stateless protocol. After the response ends, the session is terminated and the session information will not be saved. session
is generated to save the session information.
# application: represents the application, mainly used to save information at the entire application level.
# page: Represents the current page.
pageContext: page context, through which other objects can be obtained, such as request/session/application, etc.
# config: used to obtain the configuration information of the server and initialize the Servlet.
# exception: used to get the error information of the page.
You can insert java code in the JSP page, there are 3 forms of insertion:
<%! xxxxxx %>: Declaration code block, used to declare global variables or methods.
## <% xxxxx %>: java code block, in which any java code can be written, and the code block is eventually written in the method.
<%= xxxxx %>: Output code block, used to output content to the JSP page.
Improvements of JSP:
1) JSP is tabbed Text file (Servlet is a Java file) 2) JSP does not need to be compiled (in fact, the server monitors the changes in the JSP file and then translates it into Servlet code)
The server compiles it and makes the first request Create a Servlet instance. Therefore, there will be a delay when accessing the JSP page for the first time
3) JSP does not need to write a configuration file
4) JSP is mainly static code, supplemented by Java code. Servlet is the opposite.
5) It is part of the J2EE blueprint (Servlet, JSP and EJB are the three major components of J2EE)
In essence, the core of JSP is still Servlet, but it is not a substitute relationship with Servlet but a complementary relationship.
JSP is suitable for writing dynamic pages in the display layer, while Servlet is suitable for writing business control (page forwarding) in the control layer.
JSP is developing in the direction of pure tags, and Servlet is developing in the direction of pure code. They use the Servlet core (request-response working method) to develop in both directions.
The above is the detailed content of Summary of JSP basic knowledge points. For more information, please follow other related articles on the PHP Chinese website!