Home > Java > javaTutorial > body text

Summary of JSP basic knowledge points

巴扎黑
Release: 2017-07-18 14:14:27
Original
2829 people have browsed it

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
Copy after login

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"...%>
Copy after login

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"%>
Copy after login

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=""%>
Copy after login

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"/>
Copy after login

is used for page jump.

3.

<jsp:param name="paramName"value="paramValue>
Copy after login

Used in conjunction with the flag to pass request parameters when the page jumps.

五九大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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template