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.