How to answer the interview question about servlet
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.
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Guide to Random Number Generator in Java. Here we discuss Functions in Java with examples and two different Generators with ther examples.

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

Guide to TimeStamp to Date in Java. Here we also discuss the introduction and how to convert timestamp to date in java along with examples.

Capsules are three-dimensional geometric figures, composed of a cylinder and a hemisphere at both ends. The volume of the capsule can be calculated by adding the volume of the cylinder and the volume of the hemisphere at both ends. This tutorial will discuss how to calculate the volume of a given capsule in Java using different methods. Capsule volume formula The formula for capsule volume is as follows: Capsule volume = Cylindrical volume Volume Two hemisphere volume in, r: The radius of the hemisphere. h: The height of the cylinder (excluding the hemisphere). Example 1 enter Radius = 5 units Height = 10 units Output Volume = 1570.8 cubic units explain Calculate volume using formula: Volume = π × r2 × h (4
