The difference between 6.servlet and JSP

Source: Internet
Author: User

The difference between servlet and JSP

JSP is an extension of servlet technology, and often people confuse JSP with servlet. This article, will bring you the difference between servlet and JSP, hope to help you.

Servlets and JSP the Difference

1. The servlet can dynamically output HTML content through the HttpServletResponse object in Java code.

2, JSP is embedded in the static HTML content Java code, and then the Java code is executed dynamically after the HTML content generation.

Servlets and JSP of the characteristics of each

1. Although the servlet can organize the business logic code well, in the Java source file, because the Dynamic HTML content is generated by the way of string concatenation, it is easy to make the code maintenance difficult and the readability is poor.

2. JSP avoids the disadvantage of the servlet in generating HTML content, but it mixes a lot of complicated business logic into HTML.

Two swords with MVC

JSP and servlet have their own environment, then there is no way to let them play their own advantages? The answer is Ken, and the MVC pattern will solve the problem perfectly.

The MVC pattern, the abbreviation of Model-view-controller, is a software architecture model in software engineering, which is divided into three basic parts: model, view and controller:

controller--is responsible for forwarding the request and processing the request

view--responsible for interface display

model--business function writing (e.g. algorithm implementation), database design, and data access operation implementation

In the software system developed by Jsp/servlet, the descriptions of these three sections are as follows:

1. The Web browser sends an HTTP request to the server, which is then acquired by the Controller (Servlet) and processed (for example, parameter resolution, request forwarding)

2. Controller (Servlet) invokes the core business logic--model section to obtain the result

3. Controller (Servlet) gives logical processing result to view (JSP), dynamically outputs HTML content

4. Dynamically generated HTML content returned to the browser display

The MVC pattern has a great advantage in web development, which avoids the shortcomings of JSP and servlet, so that the servlet is only responsible for the business logic part, but not the HTML code, and the JSP is not flooded with a lot of business code, which can greatly improve the readability and maintainability of the code.

The difference between 6.servlet and JSP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.