JAVAEE exam short answer questions

J2EE Exam Short Answer Questions

1. Briefly describe the Servlet life cycle

Servlet life cycle (diagram) (biancheng.net)

1) Initialization phase

When the user sends an HTTP request to the Servlet container for the first time to access a certain Servlet, the Servlet container will search for the Servlet object in the entire container, find that the Servlet object has not been instantiated, then create the Servlet object, and then call the Servlet object of the object. The init() method completes the initialization.

When the user visits the Servlet for the second time, the Servlet container still searches for the Servlet object in the container, and if it finds an instance of the object, it directly uses the object without creating it.

The corresponding Servlet object is found, and then the Servlet enters the running phase.

It should be noted that in the entire life cycle of the Servlet, its init () method is only called once.

2) Operation stage

This is the most core stage in the Servlet life cycle. In this phase, the Servlet container will create a ServletRequest object and a ServletResponse object (they represent the HTTP request and HTTP response respectively) for the current request, and pass these two objects as parameters to the service() method of the Servlet.

The service() method obtains the user's detailed request information from the ServletRequest object and processes the request, and generates a response result through the ServletResponse object.

What needs to be emphasized is that during the entire life cycle of the Servlet, every time the user requests to access the Servlet, the Servlet container will call the service() method of the Servlet once, and create new ServletRequest and ServletResponse objects.

3) Destruction stage

When the server stops, the Servlet container needs to reclaim the memory occupied by the Servlet object. Before recycling, it will automatically call the destroy() method of the object to prepare for reclaiming the memory, such as closing the background thread.

Similar to the init() method, the destroy() method will only be called once.

Note: Once the Servlet object is created, it will reside in memory and wait for the client's access. The Servlet object will not be destroyed until the server is closed or the project is removed from the container.

2. Briefly describe the MVC framework

The full name of MVC is model-view-controller (model-view-controller). MVC is a pattern for developing applications. This pattern already has a good framework and is very easy to maintain. Applications developed using MVC generally include the following pieces:

(1) Controller (Controller): The controller class handles the request sent by the client to the Web application, obtains data, and specifies the view that is returned to the client to display the processing result.

(2) Model (Model): The model class represents the data of the application, and these data usually have a data verification logic, which is used to make the data must conform to the business logic.

(3) View (View): The view class is a template file used to generate and display HTML-formatted server-side responses to client-side requests in Web applications.

3. Hibernate architecture

Hibernate Architecture_w3cschool

image

  • Configuration interface: configure Hibernate, start Hibernate according to it, and create a SessionFactory object
  • SessionFactory interface: initialize Hibernate, act as a proxy for data storage sources, and create Session objects. SessionFactory is thread-safe, which means that its same instance can be shared by multiple threads of the application. It is a heavyweight and second-level cache.
  • Session interface: responsible for saving, updating, deleting, loading and querying objects. It is not thread-safe and avoids multiple threads from sharing sessions. It is a lightweight, first-level cache.
  • Transaction interface: manage transactions.
  • Query and Critical interfaces: Execute database queries.

4. Spring AOP

  • AOP means aspect-oriented programming, also called method-oriented programming. It is a technology that dynamically and uniformly adds functions to programs without modifying the source code through pre-compilation and runtime dynamic proxy. AOP technology uses a technique called "crosscutting" to dissect the inside of the encapsulated object, encapsulate the public behavior that affects multiple classes into a reusable module, and name it the Aspect aspect. The so-called aspect, in simple terms, is the logic that has nothing to do with the business, but is commonly called by the business modules. Encapsulating it can reduce the duplication of code in the system, reduce the coupling degree of modules, and make use of future operability and maintainability. .
  • AOP means aspect-oriented (aspect) programming. AOP is to reduce the coupling between codes (or modules) in the stage of implementing business processing. AOP technology is a technology that dynamically adds auxiliary functions to programs without modifying the source code through pre-compilation and runtime dynamic proxy. It is generally only applicable to applications with cross-cutting business logic, such as transaction management, log management, access rights management, and performance monitoring management.

1) Aspect aspect is a general term for cross-business logic.

2) Joinpoint connection point refers to the position (method, attribute, etc.) where the aspect can be woven into the target object.

3) Advice notification refers to the specific implementation of the aspect.

4) Pointcut entry point refers to the rules that the notification applies to which methods or properties of which classes.

5) Introduction refers to a special notification that dynamically adds methods or properties to an object.

6) Weaving refers to inserting the notification into the target object.

7) Target target object refers to the object that needs to be woven into the aspect.

8) Proxy proxy object refers to the object formed after the aspect is woven into the target object.

5. Dependency Injection

Dependency Injection DI is a programming pattern and architectural model, sometimes called inversion of control, although technically speaking, dependency injection is a special implementation of IOC. Dependency injection refers to the application of another object by one object to provide a special The ability, for example: passing a database connection parameterized form to an object's structure method instead of creating a connection within that object itself. The basic idea of ​​inversion of control and dependency injection is to convert class dependencies from inside to outside to reduce dependencies

Application of control inversion, when an object is created, an external entity that regulates all objects in the system passes the references of the objects it depends on to it. It can also be said that dependencies are injected into objects. So, inversion of control is the inversion of responsibility for how an object gets references to the objects it depends on.

The full name of IOC is Inversion of Control, also known as "Dependency Injection" or "Inversion of Control". The IOC container is used to manage beans and create a memory area for beans. In this memory area, the code for operating beans can be developed in an interface-oriented manner. From the perspective of programming technology, IOC is to separate the interface from the implementation.

6. Struts2 workflow

Architecture of Struts 2

  • The user sends a request to the server for a resource requirement (eg a page).
  • The core controller looks at the request and determines the appropriate action.
  • Configure interceptor functions with authentication, file uploads, etc.
  • Perform the selected action to complete the requested operation.
  • Additionally, configured interceptors can do any post-processing if required.
  • Finally, the results are displayed by the view and returned to the user.

Guess you like

Origin blog.csdn.net/rglkt/article/details/122336413