Servlet and JSP overview, servletjsp Overview

Source: Internet
Author: User

Servlet and JSP overview, servletjsp Overview

Speaking of Java web development, you have to mention Servlet and JSP. The two are java web development technologies. Although there are so many web frameworks, companies rarely use these two technologies to develop projects directly, but understand these two technologies, first, you will have a deep understanding of the basic web knowledge, and second, you will have a better understanding than others.

1. Servlet

1. What is servlet?

Servlet is a java program running on the Web server. Is a middle layer that is responsible for connecting databases or applications from Web browsers or other Http requests and Http servers.

2. What is the role of Servlet?

A. Read the display data sent by the user and the implicit request data sent by the browser.

Display data is generally the form data entered on the page.

Implicit data is the Http information, such as cookie, the media type that the browser can recognize or the compression mode.

B. Generate the result.

Here, we will process the business logic, such as accessing the database or other complex operations. The results and Html content that need to be directly returned to the browser will also be generated.

C. Send the display data and implicit Http response data to the customer.

Displays the data that you can see.

Http response data, such as cookie settings and cache parameters. The client browser reads and processes the information.

3. Servlet example

This example is only intended to give readers an understanding of Servlet and does not provide other configurations. Therefore, it cannot be run directly. It will be detailed later.

Package demo0103; import java. io. IOException; import java. io. printWriter; import javax. servlet. servletException; import javax. servlet. http. httpServlet; import javax. servlet. http. httpServletRequest; import javax. servlet. http. httpServletResponse; public class ServletOverview extends HttpServlet {public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String contentType = "text/html"; response. setContentType (contentType); PrintWriter writer = response. getWriter (); String docType = "<! Doctype html public \ "-// W3C // dtd html 4.01 Transitional // EN \"> \ n "; string html = "Display running results:

 

 

Ii. JSP

1. What is JSP?

JSP (Java Server Pages) is a kind of mechanism proposed by Sun Microsystems and jointly created by many companies so that software developers can respond to client requests, the technical standards of Web pages that dynamically generate HTML, XML, or other Format documents.

2. What is the role of JSP?

JSP can complete Servlet functions.

In short, Servlet can be considered as a java program containing HTML. View JSP as an HTML page containing java code.

3. JSP Example

<! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN"> Display result:

 

Servlet can complete the functions that JSP can do, and JSP can also complete the functions that Servlet can do. How to choose?

For convenience, ease of use, and maintainability, the combination is the best processing method.

Servlet is the best choice for business logic tasks.

JSP is the best choice for displayed tasks.

The MVC pattern mentioned later is a good interpretation of the two main applications.

 

The above is just your own understanding. If there is anything wrong with it, I hope to point it out.

Related Article

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.