search
HomeJavaJavaInterview questionsJavaWeb interview questions (1)
JavaWeb interview questions (1)Dec 05, 2019 pm 03:08 PM
java

JavaWeb interview questions (1)

Talk about the life cycle of Servlet?

Servlet has a good definition of life cycle, including loading and instantiation, initialization, and processing The request and service end. This lifetime is expressed by the init(), service() and destroy methods of the javax.servlet.Servlet interface. (Recommended study: java interview questions)

After the Servlet is instantiated by the server, the container runs its init method, runs its service method when the request arrives, and the service method automatically dispatches the execution corresponding to the request. doXXX methods (doGet, doPost), etc., call its destroy method when the server decides to destroy the instance.

The web container loads the servlet and the life cycle begins. Initialize the servlet by calling the servlet's init() method. This is achieved by calling the service() method, and different do***() methods are called according to different requests. To end the service, the web container calls the servlet's destroy() method.

What is the difference between forward() and redirect() in Servlet API?

1. From the address bar display,

forward means that the server requests resources. The server directly accesses the URL of the target address and puts the The response content is read and then sent to the browser. The browser does not know where the content sent by the server comes from, so its address bar is still the original address.

redirect is the server side According to the logic, a status code is sent to tell the browser to request that address again. So the address bar displays the new URL. So redirect means that the client sends two requests to the server and also accepts two responses.

2. From the perspective of data sharing

forward: the forwarded page and the forwarded page can share the data in the request.

redirect: cannot Shared data.

redirect can not only redirect to other resources of the current application, but also redirect to resources in other applications on the same site, and even redirect to other sites using absolute URLs Resources.

The forward method can only forward requests between resources within the same Web application. Forward is an operation within the server.

redirect is when the server notifies the client and allows the client to The client re-initiates the request.

So, you can say that redirect is an indirect request, but you cannot say "whether a request belongs to forward or redirect"

3. From the application Locally speaking

forward: Generally used when a user logs in, forwarded to the corresponding module according to the role.

redirect: Generally used to return to the main page and jump when the user logs out. Go to other websites, etc.

4. In terms of efficiency

forward: high.

redirect: low.

What is the difference between request.getAttribute() and request.getParameter()??

1, request.getParameter() is obtained through the implementation of the container Data passed in through methods like post, get, etc.

request.setAttribute() and getAttribute() only flow within the web container and are only in the request processing stage.

2, getAttribute returns an object, getParameter returns a string

3, getAttribute() is always used together with setAttribute(), only after setting it with setAttribute() first, The value can be obtained through getAttribute(), which passes Object type data. And it must be used in the same request object to be valid.

And getParameter() is to receive the parameters submitted by the get or post of the form

The difference between static inclusion and dynamic inclusion of jsp

1, < ;%@include file="xxx.jsp"%> is a compilation instruction in jsp. The inclusion of its file occurs during the conversion of jsp to servlet, and It is an action instruction in jsp. The inclusion of its file occurs during compilation, that is, the period when java files are compiled into class files.

2. Using static inclusion will only generate one class file, while using dynamic inclusion Multiple class files will be generated

3. Use static inclusion. The request object of the containing page and the included page is the same object, because static inclusion only copies the content of the included page to the included page;

Dynamic inclusion of the containing page and the included page are not the same page. The request object of the included page can obtain a relatively larger range of parameters. Not only can the parameters passed to the containing page be obtained, but also the parameters passed to the containing page can be obtained. You can also get the parameters passed down in the included page

What technologies are used to implement each part of MVC? How to implement it?

MVC is Model-View-Controller abbreviation. Model represents the business logic of the application (implemented through JavaBeans and EJB components), View is the presentation surface of the application (generated by JSP pages), and Controller provides process control of the application (usually a Servlet). Through this design model Divide application logic, processing and display logic into different component implementations. These components can be interacted with and reused.

What are the built-in objects in jsp? What are their functions?

JSP has the following 9 built-in objects:

1, request client request, this request will contain parameters from GET/POST request

2, response web page returns the response from the client

3, pageContext web page attribute is in Here management

4, session session related to the request

5, application servlet is executing content

6, out is used to transmit the output of the response

7, config servlet architecture components

8, page JSP web page itself

9, exception for error web pages, uncaught exceptions

Http, The difference between get and post methods

1. Get is a request to the server for data, while Post is a request to submit data to the server

2. Get is Obtain information instead of modifying information, similar to the database query function, the data will not be modified

3. The parameters of the Get request will be passed after the URL, and the requested data will be appended to the URL to? Split the URL and transmit the data. The parameters are connected with &. The XX in %XX is ASCII expressed in hexadecimal notation. If the data is English letters/numbers, send it as it is. If it is a space, convert it to, if it is Chinese. / For other characters, directly encrypt the string with BASE64.

4. There is a size limit on the data transmitted by Get. Because GET submits data through the URL, the amount of data that can be submitted by GET is directly related to the length of the URL. Different browsers have different requirements on the length of the URL. The restrictions are different.

5. The data requested by GET will be cached by the browser, and the username and password will appear in clear text on the URL. Others can check the historical browsing records, and the data is not safe.

On the server side, use Request.QueryString to obtain the data submitted by the Get method.

The Post request is sent to the web server as the actual content of the http message, and the data is placed in the HTML Header for submission. Post does not limit the data submitted. Post is safer than Get. When the data is in Chinese or insensitive data, use get because with get, the parameters will be displayed in the address. For sensitive data and data that are not Chinese characters, use post.

6, POST represents a request that may modify resources on the server. On the server side, data submitted in the Post method can only be obtained using Request.Form.

What are cookies? What is the difference between Session and cookie?

Cookie is a session technology that saves user information to the browser object.

Difference:

(1) Cookie data Stored on the client's browser, session data is placed on the server

(2) Cookies are not very safe. Others can analyze the COOKIE stored locally and conduct COOKIE deception. If security is the main consideration, session

(3) The session will be saved on the server within a certain period of time. When visits increase, it will take up more of your server's performance. If you mainly consider reducing server performance, you should use COOKIE

(4) The limit of a single cookie on the client is 3K, which means that a website is stored on the client The cookie cannot be 3K.

Conclusion:

Store important information such as login information as SESSION; if other information needs to be retained, it can be placed in COOKIE.

What are the differences, common points, and scope of application between jsp and servlet?

JSP is an extension of Servlet technology, which is essentially a simple way of Servlet. After JSP is compiled, it is a "servlet-like".

The main difference between Servlet and JSP is that the application logic of Servlet is in the Java file and is completely separated from the HTML in the presentation layer. In the case of JSP, Java and HTML can be combined into a file with a .jsp extension.

JSP focuses on views, and Servlet is mainly used for control logic. In the struts framework, JSP is located in the view layer of the MVC design pattern, and Servlet is located in the control layer.

How does the tomcat container create a servlet class instance? What principles are used?

When the container starts, it will read the web.xml files in all web applications in the webapps directory, then parse the xml files, and read the servlet registration information. Then, the servlet classes registered in each application are loaded and instantiated through reflection. (Sometimes it is also instantiated on the first request)

Add 1 when registering the servlet. If it is a positive number, then Instantiate at the beginning. If not written or is a negative number, instantiation is requested for the first time.

The above is the detailed content of JavaWeb interview questions (1). For more information, please follow other related articles on the PHP Chinese website!

Statement
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
带你搞懂Java结构化数据处理开源库SPL带你搞懂Java结构化数据处理开源库SPLMay 24, 2022 pm 01:34 PM

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于结构化数据处理开源库SPL的相关问题,下面就一起来看一下java下理想的结构化数据处理类库,希望对大家有帮助。

Java集合框架之PriorityQueue优先级队列Java集合框架之PriorityQueue优先级队列Jun 09, 2022 am 11:47 AM

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于PriorityQueue优先级队列的相关知识,Java集合框架中提供了PriorityQueue和PriorityBlockingQueue两种类型的优先级队列,PriorityQueue是线程不安全的,PriorityBlockingQueue是线程安全的,下面一起来看一下,希望对大家有帮助。

完全掌握Java锁(图文解析)完全掌握Java锁(图文解析)Jun 14, 2022 am 11:47 AM

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于java锁的相关问题,包括了独占锁、悲观锁、乐观锁、共享锁等等内容,下面一起来看一下,希望对大家有帮助。

一起聊聊Java多线程之线程安全问题一起聊聊Java多线程之线程安全问题Apr 21, 2022 pm 06:17 PM

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于多线程的相关问题,包括了线程安装、线程加锁与线程不安全的原因、线程安全的标准类等等内容,希望对大家有帮助。

详细解析Java的this和super关键字详细解析Java的this和super关键字Apr 30, 2022 am 09:00 AM

本篇文章给大家带来了关于Java的相关知识,其中主要介绍了关于关键字中this和super的相关问题,以及他们的一些区别,下面一起来看一下,希望对大家有帮助。

Java基础归纳之枚举Java基础归纳之枚举May 26, 2022 am 11:50 AM

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于枚举的相关问题,包括了枚举的基本操作、集合类对枚举的支持等等内容,下面一起来看一下,希望对大家有帮助。

java中封装是什么java中封装是什么May 16, 2019 pm 06:08 PM

封装是一种信息隐藏技术,是指一种将抽象性函式接口的实现细节部分包装、隐藏起来的方法;封装可以被认为是一个保护屏障,防止指定类的代码和数据被外部类定义的代码随机访问。封装可以通过关键字private,protected和public实现。

归纳整理JAVA装饰器模式(实例详解)归纳整理JAVA装饰器模式(实例详解)May 05, 2022 pm 06:48 PM

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于设计模式的相关问题,主要将装饰器模式的相关内容,指在不改变现有对象结构的情况下,动态地给该对象增加一些职责的模式,希望对大家有帮助。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft