Spring boot integrated servlet and jsp

Spring boot integrated servlet and jsp

1. Modify the pom.xml file, add the following

Here Insert Picture Description

2. Update maven project

3. Write servlet class (inherited HttpServlet)

Here Insert Picture Description

4. Add the servlet startup class notes

Here Insert Picture Description

5. After completion of the above steps, the parameters can be passed by way of the URL in the java class

6. java parameters to JSP added JSP storage path in the application.properties

Here Insert Picture Description

7. Create a path

Here Insert Picture Description

8. Create a control class

Here Insert Picture Description

9. Create User entity class

Here Insert Picture Description

10. Create a consistent string jsp page, the name must return the control class inside

Here Insert Picture Description

After completion of step 11. The above may be a value to pass jsp

Here Insert Picture Description
Here Insert Picture Description

Short answer:

Advantages 1. Brief spring frame

Lightweight: Spring is lightweight, basic version is about 2MB.
Inversion of Control: Spring Inversion of Control achieved by loosely coupled, objects are given their dependencies instead of creating them or find dependent objects.
Aspect-oriented programming (AOP): Spring support aspect-oriented programming, and to separate the application business logic and system services.
Container: Spring contains and manages the lifecycle and configuration objects in the application.
MVC framework: Spring WEB framework of a well-designed framework, is a good alternative to Web framework.
Transaction management: Spring provides an ongoing transaction management interface can be extended to up to lower local transaction to a global transaction (JTA).
Exception Handling: Spring API provides a convenient technique related to specific abnormalities (such as a JDBC, Hibernate or JDO thrown) into uniform unchecked exceptions.

2. Description of what is loc and DI

IOC—Inversion of Control,即“控制反转”,不是什么技术,而是一种设计思想。在Java开发中,Ioc意味着将你设计好的对象交给容器控制,而不是传统的在你的对象内部直接控制。如何理解好Ioc呢?理解好Ioc的关键是要明确“谁控制谁,控制什么,为何是反转(有反转就应该有正转了),哪些方面反转了”,那我们来深入分析一下:谁控制谁,控制什么:传统Java SE程序设计,我们直接在对象内部通过new进行创建对象,是程序主动去创建依赖对象;而IOC是有专门一个容器来创建这些对象,即由IOc容器来控制对象的创建而不再显式地使用new;谁控制谁?当然是IOC容器控制了对象;控制什么?那就是主要控制了外部资源获取和生命周期(不只是对象也包括文件等)。
Why is reversed, what reversed: there have reverse forward, legacy applications by our own initiative in an object to acquire control directly dependent objects, that is, forward; it is to be reversed by the container help create and inject dependent objects; why is reversed? Because the container to help us find and inject the dependent objects, the object of accepting it passively dependent objects, it is the reverse; what reversed? The acquisition is dependent on the object reversed. DI-Dependency Injection, namely "dependency injection": is the dependencies between components at runtime is determined by the vessel, said the image that will be injected by the container dynamic dependencies into a component. Dependency injection is not intended to bring more functionality to software systems, but to enhance component reuse frequencies, and for the system to build a flexible, scalable platform. Via dependency injection mechanism, we need only a simple configuration, without any code can specify the target resources needed to complete their business logic without having to be concerned about the specific resources come from, who to achieve. The key to understanding DI is: "Who dependence, why rely on, who is who inject, inject something" that we have to deeply analyze: Who depends on whom: of course, is application dependent on the IOC container; why the need to rely on: Application IOC container program needs to provide external resources required objects; who injection: the injection is clearly IOC container application to an object, the application-dependent objects; injecting something: an object that is injected into the external resources required (including objects, resources, constant data).
IOC and DI what does it matter? In fact, they are the same concept describing a different point of view, due to the inversion of control concepts vague (probably only be understood as a container control object this level, it is hard to think of going to protect object-relational), so in 2004 the master at Martin Fowler It has given a new name: "Dependency injection", relatively speaking IOC, "dependency injection" clearly describes the "object dependency is injected IOC container configuration dependent objects."

Guess you like

Origin blog.csdn.net/weixin_43306493/article/details/93602632