servlet interview summary

2010-09-21  来源:本站原创  分类:Java  人气:154 

1 What is Servlet
2, Servlet What is the role of
3, Servlet life cycle
4, Servlet how to handle a request
5, Servlet and JSP What is the difference
6, Servlet technology in the cookie
7, Servlet filters in
8, Servlet in the listener

I. What is Servlet?

Servlet is a program written in Java, this procedure is based on the Http protocol, running on the server side (such as tomcat),

Prepared in accordance with a Java Servlet specification class.

Second, Servlet for?

Mainly dealing with client requests and send the results to the client.

3, Servlet life cycle?

Servlet life cycle is controlled by the Servlet container, which can be divided into three stages; initialization, operation, destruction.

Initialization phase:

1, Servlet container load servlet class, the servlet class. Class files in the data read in memory.

2, and then Servlet container creates a ServletConfig object. Servlet ServletConfig object contains initialization configuration information.

3, Servlet container creates a servlet object.

4, Servlet servlet container calls the init method to initialize the object.

Operational phase:

When the servlet container receives a request, servlet container will create servletRequest for the request and servletResponse object.

Then call the service method. And these two parameters passed to the service method. Service Methods servletRequest object access request

Information. And process the request. Then the object generated by servletResponse response to this request the results. And then destroyed servletRequest

servletResponse object. We both submitted the request is post or get submitted by the end of this request will be handled by the service method.

Destruction stages:

When the Web application is terminated, servlet container will first call the servlet object destrory method, and then destroy servlet object

Will also destroy the object associated with the servlet servletConfig object. We can destroy method implementation, the release of

servlet that takes up resources, such as closing database connections, close the file input and output streams.

Where the pay attention to:

In the servlet life cycle, servlet initialization and destruction phases, and occurs only once, while the number of service methods of implementation will depend on servlet by the customer

Client visits

4, Servlet how to handle a request?

When a user sends a request to a Servlet when, Servlet container creates a ServletResponse object and ServletRequst.

In ServletRequst object encapsulates the user's request information, and Servlet containers to ServletRequst and ServletResponse objects

Passed to the user the requested Servlet, Servlet to deal with good results written in ServletResponse, and then to respond to the results of the Servlet container

To the user.

5, Servlet and JSP What is the difference?

1, jsp is compiled by the servlet, it can be said jsp equivalent servlet.

2, jsp pages also good (performance). servlet better at logic editor. (The core of the difference).

3, in practical applications to control the business process using Servlet, and JSP to generate dynamic web pages using. In the struts framework,

JSP MVC design pattern in the view layer, while the Servlet in the control layer.

6, Servlet in the cookie technology?

cookies is a WEB server through the browser the visitor's hard disk to store information means is developed by Netscape Corporation.

cookie technology benefits:

1, Cookie expiration date not yet reached the time, Cookie does not allow users to type a password and user name, entered a number of sites have been visited.

2, Cookie tracking specific visitors make site visits, last access time and the path of visitors into the site.

Create a cookie
Java code

1. / / Inside of the two parameters are the cookie name and cookie value
3. Response.addCookie (new Cookie ("abc", "10000000"));

/ / Inside the two parameters are the cookie name and cookie value

response.addCookie (new Cookie ("abc", "10000000"));

Use cookie
Java code

1. Cookie [] cook = request.getCookies ();// array receiver with a Cookie
3. For (int j = 0; j <cook.length; j ++){// Cookie through the loop to print
5. Cook [j]. GetName ():// take the name of cookie
6. Cook [j]. GetValue ():// to the cookie's value

Cookie [] cook = request.getCookies ();// array receiver with a Cookie

for (int j = 0; j <cook.length; j ++){// Cookie through the loop to print

cook [j]. getName ():// take the name of cookie
cook [j]. getValue ():// to the cookie's value


7, Servlet filters inside?

The main function of the filter

1, any system or site must determine whether the user login.

2, network chat system or forum, the text function is to filter the illegal

3, unified coding

(2) how to create a filter:

1, generates a normal class and realizes Filter Interface (javax.servlet.Filter;).

2, rewrite the interfaces inside the three methods: init, doFilter, destroy.

3, and then configure the filter in the web.xml.

8, Servlet in the listener?

The role of listener: automate some operations.

Three types of servlet listeners:

On the request of the monitor. Listening to the session. On the application of the monitor.

How to create a session listener:

1, generates an ordinary class type, if the session is listening, then realized HttpSessionListener.

2, and then rewrite the inside of the five methods:

Java code

1. Public void sessionCreated (HttpSessionEvent arg0) () / / create
3. Public void sessionDestroyed (HttpSessionEvent arg0) () / / destruction
5. Public void attributeAdded (HttpSessionEvent arg0) () / / increase
7. Public void attributeRemoved (HttpSessionEvent arg0) () / / Remove
9. Public void attributeReplaced (HttpSessionEvent arg0) () / / Replacement

public void sessionCreated (HttpSessionEvent arg0) () / / create

public void sessionDestroyed (HttpSessionEvent arg0) () / / destruction

public void attributeAdded (HttpSessionEvent arg0) () / / increase

public void attributeRemoved (HttpSessionEvent arg0) () / / Remove

public void attributeReplaced (HttpSessionEvent arg0) () / / Replacement

Statement: JavaEye article copyright belongs to the author, protected by law. Shall not be reproduced without the written permission of author.

  • servlet interview summary 2010-09-21

    ndex: 1 What is Servlet 2, Servlet What is the role of 3, Servlet life cycle 4, Servlet how to handle a request 5, Servlet and JSP What is the difference 6, Servlet technology in the cookie 7, Servlet filters in 8, Servlet in the listener I. What is

  • hibenate interview summary 2009-05-01

    hibenate interview summary. May now people often will encounter a number of these interviews, when asked the question about hibernate, I personally feel that these things were generally done in the use of development without any problems, but if you

  • Keep ing the interview summary 2011-09-02

    Interview Summary 2011/9/2 1 result will be two tables set up joint Answer: The union or union all the difference: union all is put together will result set, union is the union all the results after the then health sub-distinct, the results after rem

  • HF servlet & jsp Summary - Using JSP 2010-11-02

    At first glance HF series servlet & jsp servlet before the 6 speaker, did not have time to do sum up, the next meeting, from the "use jsp" started doing the summary, share with us, but also go over ... PS: summary of a very fragmented, but t

  • java servlet interview study notes 2010-07-16

    The process life cycle Add classLoader Examples of new Initialization init (servletconfig) Processing the request service doGet doPost Out of service destroy () Only one object api in the process: init () is executed only once, when the first initial

  • Huawei Interview Summary 2010-09-09

    The day before yesterday to attend a human outsourcing project team candidates, because the project team is to do web side, so recent has been prepared in unix command, but also in the performance optimization oracle, javascript's review and study. B

  • Interview Summary (English, constantly updated ...) 2010-11-08

    My English is limited, there are inaccuracies, please point out in reply, thank you. 1. The function of hashcode () Usually we use equals () to compare 2 objects if they are equal with our own rules. Refer to java's tradition, if you override equals

  • Servlet 2.5 new features 2009-03-29

    September 26, 2005, Sun Company and the JSR154 Expert Group on Servlet API released a new version. Under normal circumstances, a new version of JSR including only a small number of previous removal of phantom norms update. But this time, the new vers

  • [Servlet/Jsp/J2EE technical basis] 2010-03-29

    Technical base】 【Servlet/Jsp/J2EE servlet basics 1. servlet Introduction SUN like to use 'let' suffix to indicate the name of a small object, and group pieces. applet actually means little application (I always thought that when the applet beginners

  • JAVA EE JSP 2.1 2009-04-02 Actual video Han Shun ping J2EE Tutorial JSP Part 1 , paragraph 9 ----- stresses thunder: / / QUFmdHA6Ly9Bbm9ueW1vdXNANTguNTIuMTYxLjM3L7fH1K20tC9KMkVFL1u6q8uzxr1dSjJFRcrTxrXKtdW9vcyzzC9qc3AvW8DL6thdW7fH1K20t

  • Windows software Copyright Hot Comments 2010-06-03

    "The key problem is that I spend less money on windows is simply not, not enough. Do IT, should develop procedures for using the machine, if all buy legal copies, the price of heroes who now how much money we have, counted ? I now prepare a document

  • Great summary of examination questions java interview Pen 2010-03-29

    Great summary of examination questions java interview Pen Great summary of examination questions java interview Pen First, to talk about the final, finally, finalize the difference. Most frequently asked. Second, Anonymous Inner Class (anonymous inne

  • Great summary of java interview questions document 2010-06-06

    Great summary of java interview questions document Basic knowledge JAVA 1, object-oriented features are what 1. Abstract: Abstract is to overlook a topic unrelated to the current target those aspects in order to more fully pay attention to related as

  • Summary SSH interview questions 2010-12-23

    Summary SSH interview questions MVC 1. Talk about your understanding of mvc MVC is the Model-View-Controler for short. The Model - View - Controller. MVC is a design pattern that the mandatory application of the input, processing and output separatel

  • Sql common interview questions (summary) 2011-05-23

    Sql common interview questions (summary) 1. Using a SQL statement to query the records were more than 80 names of students name kecheng fenshu Joe Smith 81 languages Zhang San Mathematics 75 John Doe 76 languages John Doe 90 Mathematics King Five Lan

  • Spring, struts, hibernate common interview questions document summary (1) 2010-09-11

    (Transfer from: ) Spring, hibernate, struts interview questions document 1, Hibernate works and why to use? Principle: 1. To read and parse the configuration file 2. To read and parse the

  • Spring, struts, hibernate common interview questions document summary (2) 2010-09-11

    (Transfer from: ) 1.Struts in Action is a thread-safe? If not, please say why. In Struts you can define a static variable? Reference answer: Servlet is a multi-threaded environment. That t

  • jsp and servlet garbled learning summary 2010-10-27

    WEB resolve coding problems during the development of web development, the problems often encountered garbled, garbled generally appear in: 1. Jsp file written in Chinese garbled 2. Pages have become garbled in Chinese 3. Back through request.getPara

  • web entry summary of common errors when the servlet 2010-11-07

    The most common path error, as long as you understand the following points deep , You will be able to successfully resolve . ■ < servlet > Elements < servlet > <!-- Servlet Name --> < servlet -name>Servlet</ servlet -name> &l

  • Summary 2010 J2EE interview questions 2010-12-13

    State! If identical, very happy! Popular frameworks and new technologies 1 , talk about your understanding of Struts. A: 1. Struts MVC pattern is designed by Web layer framework, in fact, it is a big servlet, the Servlet called ActionServlet, or a su