Home > Java > javaTutorial > body text

How to answer the interview question about servlet

(*-*)浩
Release: 2019-05-17 14:19:31
Original
2827 people have browsed it

Different interviewers focus on different directions. However, if you ask about Servlet, the following content will most likely be asked. It can be used as a reference. There are only so many questions about Servlet without mentioning it.

How to answer the interview question about servlet

1. Servlet life cycle

Initialization: The web container loads the servlet and calls the init() method;

Processing requests: Allow the service() method, service() automatically runs the doXXX method (doGet or doPost) corresponding to the request

Destruction: After the service ends, the web container calls the servlet's distory() method to destroy the servlet

2. What is the difference between jsp and servlet.

jsp is essentially a servlet, but the two are created in different ways. servlets are composed of java program code and are used for process control and transaction processing, while jsp is composed of html and jsp tags, which can Write dynamic web pages easily. There are two main differences between jsp and servlet: Compilation: After jsp is modified, you can see the effect immediately without compilation, while servlet requires compilation. Conversion: jsp is a dynamic web development technology and a scripting language that runs on the server side, while servlet is a web server programming technology, so jsp is converted into servlet when it is run.

3. What is the difference between get and post?

The get parameter is passed through the url, and the post is placed in the request body;

The get request parameter has a length Limitation, post is not as safe as

get because the parameters are exposed in the url.

Get requests can only be URL encoded. Post supports multiple encodings

Get request parameters will be completely retained in the browsing history, but post will not be retained.

Get and post are essentially tcp links, there is no difference. However, due to HTTP regulations and browser/server limitations, they show some differences in the application process.

get generates one tcp data packet; post generates two tcp data packets.

4. What are the two parameters of the doGet and doPost methods?

HttpServletRequest: Encapsulates information related to the request

HttpServletResponse: Encapsulates the response Related information

5. What are the built-in objects of jsp?

request: Contains the information requested by the client

response: Contains the information returned by the server to the client Response information

session: The session period related to the request

pageContext: Manage web page properties

application: Server startup creation, server shutdown stop, save information for multiple applications

out: transmit data to the client

config: the architectural component of the servlet

page: refers to the web page itself

exception: can only be used for error pages

6. Four scopes

page: a page

request: a request

session: a session

application: server from start to stop

7. What is the difference between dynamic include and static include in jsp

Dynamic include is implemented with jsp:include action< ;jsp:include page="include.jsp" flush="true"/> It will always check changes in the included files. It is suitable for including dynamic pages and can take parameters.

Static include is implemented using include pseudocode, and changes in included files will not be checked. It is suitable for including static interfaces<%@ include file="included.htm"%>

8. The difference between forward and redirect

Forwarding and redirection:

The first point: From the address bar, forward means that the server requests resources, and the server directly accesses the target address. URL, read the response content of the target URL, and then send it to the browser. The browser does not know where the content sent by the server comes from, so the address bar is still the original URL. Redirect means that the server sends a status code based on logic to tell the browser to request that address again, so the address bar will display the new URL.

Second point: In terms of data sharing, the forward page and the forwarded page share the data in the request, and redirect cannot share data.

The third point: From the perspective of running location, forward is generally used when logging in, forwarding to the corresponding module according to the role.

Redirect is generally used when users log out and log in to return to the homepage or jump to other pages.

The fourth point: In terms of efficiency, forward is high and redirect is low.

The above is the detailed content of How to answer the interview question about servlet. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template