The difference between jsp and servlet

basic concept

1. Servlet

Servlet is a server-side Java application with platform and protocol-independent characteristics, which can generate dynamic Web pages. It acts as an intermediary between client requests (web browsers or other HTTP clients) and server responses (databases or applications on HTTP servers). A servlet is a server-side Java application located inside a web server. Unlike traditional Java applications that are started from the command line, servlets are loaded by a web server, which must contain a Java virtual machine that supports servlets.

2. JSP

The full name of JSP is Java Server Pages, and the Chinese name is java server page, which is basically a simplified Servlet design.

JSP technology uses the Java programming language to write XML-like tags and scriptlets to encapsulate the processing logic for generating dynamic web pages. Web pages can also access application logic for resources that exist on the server side through tags and scriptlets. JSP separates web page logic from the presentation of web design, supports reusable component-based design, and makes the development of web-based applications quick and easy. JSP (JavaServer Pages) is a dynamic page technology whose main purpose is to separate presentation logic from Servlet.

Similarities between JSP and Servlet

JSP can be regarded as a special servlet, it is just an extension of servlet, as long as the work that can be done by JSP can be done by using servlet, such as generating dynamic pages. Since the JSP page will eventually be converted into a servlet to run, processing the request is actually a compiled servlet.

Difference between JSP and Servlet

1. Good at convenience

  • Servlet is implemented by embedding HTML code in java code. It is very inconvenient to write and modify HTML, so it is suitable for process control and business logic processing.
  • The way JSP is implemented is to embed java code in HTML, which is more suitable for page display

2. Built-in objects

  • There are no built-in objects in servlets

  • The built-in objects in JSP must be obtained through the HttpServletRequest object, the HttpServletResponse object and the HttpServlet object.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325805290&siteId=291194637