JavaServer Pages(JSP) is a server-side programming technology that creates dynamic, platform-independent methods for building Web-based applications. JSPS can access the entire family of Java apis, including the JDBC API for accessing enterprise-level databases.

This article helps beginners understand the basic functionality of JavaServer Pages(JSPS) to develop their own Web applications.

You’ll find yourself at a moderate level of JSP expertise, and you can move up to a higher level.

To share this SET of JSP video tutorial, explain very detailed, video content is mainly composed of two parts:

  • The first part is the JSP foundation. Mainly explained JSP specification, JSP annotation, JSP code block, statement block and expression block.
  • The second part is JSP core. It mainly explains nine built-in objects, JSP common instructions, JSP common actions, custom EL function and EL common usage, custom tag usage, JSTL usage.

Watch online:www.bilibili.com/video/BV1ax…

Information download:www.bjpowernode.com/javavideo/2…

What is a JSP?

JSP full name Java Server Pages, is a dynamic web development technology. It uses JSP tags to insert Java code into HTML web pages. Tags usually start with <% and end with %>.

JSP is a Java servlet that is primarily used to implement the user interface portion of a Java Web application. Web developers write JSPS by combining HTML code, XHTML code, XML elements, and embedded JSP actions and commands.

JSP uses web forms to get user input data, access databases and other data sources, and create web pages on the fly.

JSP tags have various functions, such as accessing databases, logging user selection information, accessing JavaBeans components, and passing control and sharing information across different web pages.

JSP characteristic

● Dynamic web content can be easily and efficiently added in a templated way.

● Can use JavaBean and tag library technology reuse commonly used functional code (designed components easy to achieve reuse, reduce repeated labor). The tag library not only comes with generic built-in tags (JSTL), but also supports extensible custom tags.

● Good tool support.

● Inherits the relative ease of use of the Java language.

● Inherit the Java cross-platform advantages, to achieve “write once, run everywhere”. Because support Java and its related technology development platform, website developers can choose the most suitable for their own system platform JSP development; JSP projects developed in different environments can be accessed smoothly on all clients.

“Page in the dynamic part of the (content change control)/static area (content does not need to change part) in the form of scattered but orderly together, can make people more intuitive to see the overall structure of the page code, also makes the design page this 2 part easy separation effect and the program logic (exterior view with logic separation). Thus convenient distribution of personnel and play to their strengths, to achieve efficient division of labor and cooperation.

● Compatible with other enterprise-class Java technologies. JSP can only be responsible for the presentation of data in the page, to achieve hierarchical development.

The JSP specification

I. Introduction:

  1. JSP is a specification provided by Sun

  2. The JSP specification is used to encapsulate the response object to make it easier to write Servlet processing results into the response body

Second, the problem of using the response object

  1. Set the response header content-type manually

  2. Manually request an output stream object

  3. Manually write the result to the response body

Three, JSP advantages

As a developer, you just have to think about what you need to write into the response body and not the process of writing into the response package

The JSP file “runtime” automatically writes everything inside the file that has nothing to do with Java commands () to the response body

Java command writing specification in JSP file

1. Execute the label

1) Format: :

<% Java command line; % >Copy the code

2) Function: used to prompt JSP file at run time do not write the Java command in the execution tag to the response body notice JSP file at run time need to execute the content in the execution tag before output

3) Java command line

  • Declare a variable
  • Declare operation expression [mathematical, relational, logical operation]
  • Declare control statements and loop statements
  1. The output label

1) Format: :

<%= Variable name %> <%= Operational expression %>Copy the code

2) :

When the JSP file is run, the JSP is told to write the specified variable content or expression result to the response body

Built-in object in JSP file — 9

1.ServletContext application

2.HttpSession session

3.HttpServletRequest request

The relationship between Servlet and JSP files

1. Servlets: Receive requests and process them, but the Servlet is not responsible for returning the results

—– is equivalent to “Chef”

2.JSP: is not responsible for processing the request. It is responsible for writing the processing result generated by the Servlet to the response body

—– is equivalent to “the waiter”

3. Call relationship between Servlet and JSP

Forward requests

Browser — — — — — – > Servlet (request) — — — — — — — — — — — — — — > > JSP processing result written to the response body

4. How to share data between Servlet and JSP with request

Seven, JSP operation principle 【 interview 必考题】

1.JSP files are neither static nor dynamic resource files

2.JSP files cannot be compiled and executed

3. Operation principle:

1) When Tomcat receives a request to call the JSP file (one.jsp), tomcat will call the JSP [edit] as the Java file (one_jsp.java).

2) Tomcat calls the JVM to convert the Java file into a class file (one_jsp.class)

3) This class file is a Servlet interface implementation class

4) Tomcat uses reflection to generate instance objects of this class file

5) Tomcat calls the _jspService method through the instance object, which is responsible for writing the JSP file contents to the response body via the output stream at run time