Summary of JSP basic knowledge points
1 Overview
1. What is JSP?
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 .
Second path
1. Absolute path
The resource can be uniquely determined by itself The path starts with the protocol, such as http in an HTTP request.
2. Relative path
You must rely on other paths to uniquely determine the path of the resource, and the content does not start with a protocol.
3. Resource path composition
Access path + resource name, the resource name is the content after the last "/", and the rest is access path.
4. WEB-INF 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
5. Redirect path
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.
6. Forwarding path
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.
Three command tags
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:
1.page
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.
2.include
<%@ 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.
3.taglib
<%@ 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 .
Four action identifiers
There are 3 action identifiers in JSP:
1.< ;jsp:include>
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.
2.
<jsp:forward page="url"/>
is used for page jump.
3.
<jsp:param name="paramName"value="paramValue>
Used in conjunction with the
五九大built-in objects
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.
Six java codes
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

Summary of the system() function under Linux In the Linux system, the system() function is a very commonly used function, which can be used to execute command line commands. This article will introduce the system() function in detail and provide some specific code examples. 1. Basic usage of the system() function. The declaration of the system() function is as follows: intsystem(constchar*command); where the command parameter is a character.

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

Usage: In JavaScript, the insertBefore() method is used to insert a new node in the DOM tree. This method requires two parameters: the new node to be inserted and the reference node (that is, the node where the new node will be inserted).
