Simple J2EE (5) Servlet and JSP

Source: Internet
Author: User

Each time a servlet sends a request, it starts a thread.
The servlet remains alive after the request ends.
Servlet has four basic methods: Init (), service (), Request Method (dopost/doget), and destroy (). We can overwrite the init () method and add the statements that only need to be executed once in the servlet lifecycle. The Service () method will generate a new thread for the request or call unused threads. Pay attention to the concurrency problem here. A simple way of processing is to implement singlethreadmodel, however, this may reduce performance.

 

JSP is essentially a servlet. When the client requests this JSP for the first time, it will compile the JSP into a servlet. Since JSP was first positioned to be visible to page developers, the syntax is simple and a lot of markup is used.

Five tags in JSP:
<%--%>: Annotation mark

<%! %>: Declaration mark

<% @ %>: Command tag. There are three types of import, include, and taglib, which respectively correspond to the corresponding classes, files, and tag libraries imported to JSP files.
Example: <% @ page import = "Java. SQL. * "; %> <% @ include file =" books.html "%> <% @ taglib uri =" mytags. TLD "%>

<% = %>: Expression mark

<%>: Script tag

JSP can provide the same functions as servlet. Therefore, the servlet object JSP also has the following functions: request, response, session, and 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.