Java web part - face questions

1, Tomcat optimization experience

A: remove the monitoring of web.xml and the editor jsp advance into Servlet.

A surplus of physical memory, the increased use of tomcat jvm memory

 

2, Servlet life cycle

Answer: servlet has a well-defined lifetime, including loading and instantiation, initialization is complete, process the request and services. The survival of javax.servlet.Servlet interface init, express service and destroy methods.

After Servlet is instantiated server, container runs its init process runs its service method when a request arrives, the service method of automatically sending doXXX method of operation corresponding to the request (the doGet, the doPost   Jsp page FORM tag's method attribute to get the call doGet (), is when the post calls doPost () ), etc., when the server decides to destroy the instance when calling its destroy method.

web container loads the servlet, life cycle begins. Initializes the servlet by calling the servlet's init () method. Achieved by calling the service (), according to different call requests do *** () method. End services, web container calls destroy servlet's () method

public class ServletName extends HttpServlet { 
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 

    } 
   public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 

    } 
} 

3. redirect forwarded difference between

1, forward server-side steering is forwarding the request and redirect the jump-client is redirected

2, the use of forward browser's address does not change. The redirect will change.

3, forward a request is completed. The redirect is to re-initiate the request.

4, forward is the server side, rather than the client request to reinitiate high efficiency.

 

 

1, request forwarding features:
1 "request only once, and belong to the internal Jump
2" changes the address bar does not happen
3 "does not allow access to external resources
4" / representatives after the absolute path of the root directory
5 "high efficiency
forwards the request syntax:

request.getRequestDispacher (address) .forward (request object, the response object)

 

2, redirection features:
1 "The whole process of issuing two requests
2" address bar will change, and jump to the new page, the page address in the address bar is the latest of
3 "to allow access to external resources because the server has responded back the browser, and the browser also issued a new request, since HTTP is stateless so the two requests did not contact, a second request can go to any random page
4 "/ behalf absolute path is the port number after
5" low efficiency, because there are two requests, relatively inefficient
redirection syntax:
Response.sendRedirect (address)

 

4, jsp nine built-in objects

request the client request, the request will include parameters from GET / POST request

response page returns a response to the client's

PageContext property management page is here

session related to the request of the session

Content application servlet is being executed

out for the transmission output response

config servlet framework member

page JSP page itself

exception for error pages, uncaught exception

 

request represents the HttpServletRequest object. It contains information about the browser request, and provides a useful way to get a few cookie, header, and session data.

HttpServletResponse object represents a response, and provides several methods for setting response back to the browser (e.g., as cookies, header information, etc.)

out object is an instance of javax.jsp.JspWriter, and provides several ways so that you can be used to send output back to the browser.

pageContext represents a javax.servlet.jsp.PageContext object. It is used to facilitate access to a diverse range of name space, the API associated servlet object, and a method of packaging a general-purpose functions associated servlet.

 It represents javax.servlet.http.HttpSession session object requested. Session state can store user information

 applicaton represents a javax.servle.ServletContext object. This helps to find information about the servlet engine and servlet environment

 config represents a javax.servlet.ServletConfig object. This object is used to access the servlet instance initialization parameters.

 It represents a page from the servlet instance generated page

 

5, JSP and Servlet What are the similarities and differences What is the connection between them is?

JSP is an extension of the Servlet technology, Servlet is a simple way of essence, more emphasis on the appearance of the application of the expression. After the JSP compiler is "class servlet". Servlet and JSP main difference that the application logic is a Java Servlet file, and completely separated from the HTML presentation layer. The situation JSP is Java and HTML can be combined into a .jsp file extension. JSP focuses on view, Servlet mainly for control logic.

 

1, forward server-side steering is forwarding the request and redirect the jump-client is redirected

2, the use of forward browser's address does not change. The redirect will change.

3, forward a request is completed. The redirect is to re-initiate the request.

4, forward is the server side, rather than the client request to reinitiate high efficiency.

 

 

1, request forwarding features:
1 "request only once, and belong to the internal Jump
2" changes the address bar does not happen
3 "does not allow access to external resources
4" / representatives after the absolute path of the root directory
5 "high efficiency
forwards the request syntax:

request.getRequestDispacher (address) .forward (request object, the response object)

 

2, redirection features:
1 "The whole process of issuing two requests
2" address bar will change, and jump to the new page, the page address in the address bar is the latest of
3 "to allow access to external resources because the server has responded back the browser, and the browser also issued a new request, since HTTP is stateless so the two requests did not contact, a second request can go to any random page
4 "/ behalf absolute path is the port number after
5" low efficiency, because there are two requests, relatively inefficient
redirection syntax:
Response.sendRedirect (address)

 

4, jsp nine built-in objects

request the client request, the request will include parameters from GET / POST request

response page returns a response to the client's

PageContext property management page is here

session related to the request of the session

Content application servlet is being executed

out for the transmission output response

config servlet framework member

page JSP page itself

exception for error pages, uncaught exception

 

request represents the HttpServletRequest object. It contains information about the browser request, and provides a useful way to get a few cookie, header, and session data.

HttpServletResponse object represents a response, and provides several methods for setting response back to the browser (e.g., as cookies, header information, etc.)

out object is an instance of javax.jsp.JspWriter, and provides several ways so that you can be used to send output back to the browser.

pageContext represents a javax.servlet.jsp.PageContext object. It is used to facilitate access to a diverse range of name space, the API associated servlet object, and a method of packaging a general-purpose functions associated servlet.

 It represents javax.servlet.http.HttpSession session object requested. Session state can store user information

 applicaton represents a javax.servle.ServletContext object. This helps to find information about the servlet engine and servlet environment

 config represents a javax.servlet.ServletConfig object. This object is used to access the servlet instance initialization parameters.

 It represents a page from the servlet instance generated page

 

5, JSP and Servlet What are the similarities and differences What is the connection between them is?

JSP is an extension of the Servlet technology, Servlet is a simple way of essence, more emphasis on the appearance of the application of the expression. After the JSP compiler is "class servlet". Servlet and JSP main difference that the application logic is a Java Servlet file, and completely separated from the HTML presentation layer. The situation JSP is Java and HTML can be combined into a .jsp file extension. JSP focuses on view, Servlet mainly for control logic.

 

Guess you like

Origin www.cnblogs.com/huoyuer/p/11235610.html