Summary of question (a)

1. Talk about the difference between the jetty and tomcat.

Same point:

  • tomcat and jetty is a kind of servlet engines , they support the servlet specification and standard specification javaEE

difference:

  • jetty faster, more flexible, smaller kernel. Default utf-8 character set, Chinese garbled absence , but not suitable for large-scale open.
  • tomcat more traditional, more powerful, especially for large-scale development projects, but often there are Chinese garbled situation , ISO_8859_1 default character set.

2. How to modify the default port jetty? How to modify the default port tomcat?

2.1 modify the default port jetty

  • Start.ini open files in the installation directory jetty
    Here Insert Picture Description
  • The port changes as shown below: 8888
    Here Insert Picture Description

2.2 modify the default port tomcat

  • Open server.xml file tomcat installation directory of
    Here Insert Picture Description
  • The port changes as shown below: 8080
    Here Insert Picture Description

3. How to Start jetty server?

Under normal circumstances can be activated by installing the package directory start.jar jetty, in addition, can also dos command, first enter the jetty installation folder, and then enter the command to start.
Start command: java -jar start.jar
Here Insert Picture Description

4. Description of the life cycle of the Servlet.

(1) loading and instantiating
when starting Servlet container or the client sends a request, will find whether the Servlet container Servlet example stored in memory, if present, directly read the example response to the request directly to the step (3); If not, then by the constructor to create a Servlet examples.
(2) Initialization
instantiated, Servlet container calls the Servlet init () method to initialize (or some preparation work resource preload).
(3) service
initialization, Servlet can be in a ready state in response to the request. Upon receiving the client request, call service () method of handling client requests, the HttpServlet's service () method will transpose doXxx different depending on the request () method: the doGet () and the doPost () .
(4) destroyed
during re-released project, normally closed tomcat, will perform the destroy () method, if the non-normal shutdown, the equivalent of program interruption, the method will not be executed.

//从左到右的次序
1.如果是第一次请求。
                           --->doGet
   构造方法-->init-->service            --->destroy
                           --->doPost

 2.如果不是第一次请求

   说明这个servlet已经驻留内存了。

             --->doGet
   service --             ---->destroy
             --->doPost

5. Servlet how to handle the user's request?

  • For each request of Servlet, Web servers in call service () method before, will create a HttpServletRequest and HttpServletResponse objects. Referred to as the request and response objects. Servlet browser to access the interactive process is shown below:
    Here Insert Picture Description
  • First the browser to the Web server sends an HTTP request , the Web server, upon request, will first create a HttpServletRequest and HttpServletResponse objects , and then call the appropriate Servlet program .
  • In Servlet run , it first reads the information from the HttpServletRequest object data , and then through the service () method for processing the request message , and writes the processed data in response to the HttpServletResponse object . Finally, Web server will be from HttpServletResponse object reads the response data sent to the browser .

6. Talk about the difference between the post and request a get request.

Same point:

  • get and post are http request method. (Http request method is far more than these two)

difference:

  • get request focus on access to resources from the server , and post requests focus on sending data to the server .
  • get request during its parameters in the browser visible url address bar , so privacy is poor security, and the parameter length limitations , and post requests the parameters passed in the Request body, not in the address bar url display , safer than GET, and the parameters of unlimited length .
  • get request more common way is by request url address bar , and post the request of the most common is to send a data request form by form .

7. Talk about the difference between relative and absolute address address.

  • Relative address relative to the current address of the resource. Error-prone, simple wording .
  • Address absolute address universal. Certainly can not go wrong, spell more trouble .
  • For example : Suppose your web page in the following location: D: \ WORK \ web \ 111.html, and pictures in D: \ WORK \ web \ images \ 111.jpg, the following two situations:
    ① you directly to the page in D: \ WORK \ web \ images \ 111.jpg this path represents your picture. <This is the picture of the absolute path>
    ② you to the page: images \ 111.jpg to represent you in this picture. <This is a relative path pictures>

8. The difference between the talk request redirection request forwarded.

Redirect the request (redirect):

  • Syntax: response.sendRedirect (url); requires two requests, the address bar will change,
    request objects have become, and the request in the property can not be saved.

Request Forwarding (forward):

  • Syntax: request.getRequestDispatcher (url) .forward (request, the Response); need a request, the address bar will not change, request the same objects and attributes can be saved in the request.

9. jsp which has nine built-in objects? How to get servlet session and application objects?

  • jsp nine built-in objects : out, page, request, response , session, application, exception, pageContext, config
    which is commonly used: request, response, session, application
  • Gets session object :
    . Request.getSession () setAttribute ( "name", "Taipan"); // get big fat as this object
  • Gets the application object :
    . Request.getServletContext () setAttribute ( "Nation", "china"); // this object such as access to China

10. What is a singleton? What singleton design pattern?

  • Example Java single defined as: only one instance of a class and have, and examples of their own available to the entire system.
  • Mode and the single idler embodiment has a hungry man mode .
    Metaphor: a hungry man take the initiative to find food to eat, lazy people lying on the ground waiting to feed.
public class MySun {
    //懒汉模式
    private static MySun sun; //单例对象

    private MySun(){ //私有构造方法

    }
   //静态工厂方法
    public static MySun getInstance(){
        if(sun==null){
            sun = new MySun();
        }
        return sun;
    }
}

① To get a class can only build an object, naturally can not just let it do new operation, so MySun constructor is private.
②sun static members MySun class, but also our singleton object. Its initial value can be written null, can also be written new MySun ().
③getInstance () Gets a singleton object. If the initial value is singleton null, yet build, the build object and returns a single embodiment. The wording in the embodiment are single lazy mode . If the singleton object outset is new MySun () active construct, null judgment operation is no longer necessary, such an approach belonging hungry man mode .

Published 62 original articles · won praise 2 · Views 2725

Guess you like

Origin blog.csdn.net/nzzynl95_/article/details/104300100