Servlet Programming Basics Overview-mvc Control layer

Source: Internet
Author: User

To introduce the servlet has a lot of text, I believe some friends like me hate to read a lot of text, I long story short:

As we have concluded, we use JavaBean programming to separate the HTML code of the Java code from the JSP file, but we cannot use the JSP built-in object in Java code, that is, JavaBean cannot use the request, Response and other objects to receive and transmit page information, only to achieve simple static functions.

A servlet is a dynamic reference to request, response ... Java class that runs on the server side like JavaBean. We call this the middle control layer (the controls) this is the Classic programming mode MVC programming pattern, the specific thing I will share with you in the next blog.

How the servlet is used I will not elaborate, a simple example: to find the area of the circle. The RADIUS information of the circle is sent from the client, which is then received by the servlet and returned to the client after the area is calculated.

First create a Srevlet class, write the Doget and Dopost functions, the other parts are automatically generated, do not need to write their own.

Second, we need to modify the Web site configuration file, XML, to add the following content: (Most of the eclipse is now automatically generated servlet configuration information, or can see)

For a detailed explanation of the comments in the code, finally we build a JSP to invoke the servlet:

OK, let's test it out:


Summary: Now we can see that the client interface is still only very short code, the middle of the process is running on the server side.

JavaBean can only handle static functions of the Java class and cannot get the parameters of the client. A servlet is a Java class that can fetch parameters from a client. What JavaBean and servlets have in common are performed on the server side. So, the intelligent human thought of the MVC programming pattern, that is, after the client submits the parameters-the server uses the servlet to retrieve the parameter information-and then the corresponding parameter calls the JavaBean method to implement the calculation-and then returns the result to the client.

Servlet Programming Basics Overview-mvc Control layer

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.