1. What is the servlet lifecycle? What is the difference between Servlet and CGI?
A: When a Web container loads servlet, the lifecycle begins. Call the servlet Init () method to initialize the servlet. By calling the Service () method,
Call different do *** () methods based on different requests. End the service. The Web Container calls the Servlet's destroy () method.
The difference with CGI is that the servlet is in a server process and runs its service method in multiple threads. An instance can serve multiple requests,
In addition, the instance will not be destroyed, and CGI will generate a new process for each request, and the service will be destroyed after completion, so the efficiency is lower than servlet.
2. Describe the differences, commonalities, and application scopes between JSP and servlet.
A: Although JSP is essentially a servlet, the two are created in different ways. servlet is completely composed of Java program code and is good at Process Control and transaction processing.
It is not intuitive to generate dynamic web pages. jsp consists of HTML code and JSP tags, which can be used to conveniently compile dynamic web pages. Therefore, servlet is used in actual applications to control business processes.
JSP is used to generate dynamic web pages. In the Struts framework, JSP is located at the view layer of the MVC design mode, while servlet is located at the control layer.
3. What are the similarities and differences between the user's request to access the HTML page and the servlet?
Same: both use the HTTP protocol. difference: the latter must configure the URL path in Web. xml.
Example: assume that there is a helloservlet class in the helloapp application. Its configuration in the web. xml file is as follows:
<Servlet>
<Servlet-Name> helloservlet </servlet-Name>
<Servlet-class> org. javathinker. helloservlet </servlet-class>
</Servlet>
<Servlet-mapping>
<Servlet-Name> helloservlet </servlet-Name>
<URL-pattern>/Hello </url-pattern>
</Servlet-mapping>
The URL for accessing helloservlet on the browser is:
Http: // localhost: 8080/helloapp/Hello
4. What are JSP commands?
A: JSP commands are divided into two types: Page commands and action commands.
Action Commands include usebean, setproperty, getproperty, forward, plugin, and include.
How does JSP use annotations?
Answer: 1) <% -- %> 2); //; 3)/*****/; 4) <! -->;