About Servlets and JSPs

Source: Internet
Author: User

the difference between servlet and JSP

1, the first servlet, and then JSP. servlet design, the function is very powerful, the system design is also very advanced, but it output HTML using the old-fashioned CGI, one sentence to output HTML, which makes it inconvenient to write and modify HTML, and then Sun launched a similar to the ASP Mosaic JSP, the JSP Tag mosaic into the HTML statement, this greatly simplifies the design and modification of the Web page, the new network language ASP, PHP, JSP, etc., are mosaic script language
2, the two are created differently:
There are three ways to create a servlet:
1. Implement the Servlet interface and rewrite the service method
2. Inheriting the Genericservice class, overriding the Service method
3, Inherit HttpServlet (Common), rewrite doget (), DoPost () method
JSP creation, directly create a JSP file, similar to HTML, just need to introduce the page tag in the first line of the JSP file <% @page contenttype= "text/html" pageencoding= "UTF-8"%>
3, the servlet is completely composed of Java code, good at process control and transaction processing, generated by the servlet Dynamic Web page is not intuitive; JSP is composed of HTML code and JSP tags, can easily write dynamic Web pages, so in practical applications, Use Servlets for Process Control and JSP to generate dynamic Web pages
4. In the MVC design pattern, the JSP is in the view layer, and the servlet is in the control layer
5, JSP is the development of servlet technology, in essence is the simple way of servlet
6. The application logic of the servlet is in the Java file and is completely separate from the presentation layer's HTML code, and the JSP is a combination of Java and HTML. jsp file
7, JSP focus on the view, servlet focus on logical control

is the servlet thread-safe?

1, the servlet default is a singleton mode, there is only one instance in the Web container, so when multiple threads access a servlet at the same time, the servlet is thread insecure
2. However, the Web container can also create a servlet instance for each request, requiring only the servlet to implement the Singlethreadmodel interface.
There are two points:
1. Each servlet creates an object instance when it is accessed, consumes memory resources
2, each srvlet can only support concurrent access of 20 threads at the same time, the Web server will automatically suspend the access thread after 20

when to invoke the Doget () and Dopost () methods

When a request is sent in a Get mode, the Doget () method is called, and the page defaults to a GET request for a background resource
When a request is sent by post, the Dopost () method is called, and the POST request is sent only when the form form's action is specified as a POST request or an AJAX request that specifies the request mode as post.

About Servlets and JSPs

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.