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
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!

The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.

The article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

The article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]

Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa


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

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Chinese version
Chinese version, very easy to use