Recently in the interview, found some questions about servlet/jsp, memory is a bit vague, so do a little of this summary as follows:
1, the difference between servlet and GCI?
A: The servlet is written in Java, in a server process, it can run the service () method in a multithreaded manner, one instance can serve multiple requests, and generally will not be destroyed, while CGI produces a new process for each request, the service is destroyed after completion, So the efficiency is lower than the servlet.
2. Remember the life cycle of the servlet?
A: The servlet's life cycle starts with the web load servlet, invokes the servlet's init () method to initialize the servlet, processes the request by invoking the service () method, and invokes the different methods according to the different requests. The service ends, and the Web container invokes the servlet's Destroy () method.
3, JSP is the extension of servlet technology, more emphasis on the processing of the performance layer. The main difference between servlet and JSP is that the server side has a JSP container, which mainly handles JSP page requests, the container first turns the JSP into a servlet, all the JSP elements are converted to Java code, and then the Servlet class is compiled. JSPs focus on Views, and Servlets are primarily used to control business logic.
4. What are the built-in objects for JSP? What are the roles?
· Request object for the HttpServletRequest class: represents the requested object and is used primarily to receive data transmitted by the client over an HTTP protocol connection to the server
· The response object of the HttpServletResponse class: Represents the Response object and is used primarily to respond to the client to send data.
· The Application object of the ServletContext class: primarily used to hold common data in all applications, it is a shared built-in object, that is, multiple users in a container share a Application object, as long as the server is not shut down, Application always exists.
· Session object of the Httpsessoin class: used primarily to distinguish between each user information and session state.
· The PageContext object of the PageContext class is mainly used to manage page properties, represents the context of a page, and the creation and initialization of PageContext objects are automatically done by the container.
· The Page object of the object class: Represents a running JSP page, which means that the Page object represents the JSP's compiled servlet. The Page object can only be used within the current JSP scope.
· Config object for the ServletConfig class: A code Snippet Configuration object that initializes the configuration parameters for the servlet.
· Out object of the JspWriter class: used primarily to output data to the client.
Exception object: Handles errors and exceptions that occur when the JSP file executes, as long as the error page is used.
5, say the JSP 6 action instructions and role?
Jsp:include: Introduce a static or dynamic file when the page is requested.
Jsp:usebean: Seek or instantiate a javabean.
jsp:setproperty: Sets the properties of the JavaBean.
jsp:getproperty: Gets the properties of a JavaBean.
Jsp:forward: Move the request to a new page (HTML file, JSP file, or a program segment).
Jsp:plugin: Generates an object or embed tag for the Java plug-in based on the browser type.
6, JSP 3 ways to jump
response.sendredirct () method: Resend the request.
Response.setheader () method: With the Response.sendredirect () method.
<jsp:forward page= "Jump page"/>: is a server-side jump.
SERVLET/JSP Interview Topic-----Recent Summary