Jsp-servlet provides a good platform for Web application developers. However, most of the domestic development based on Jsp-servlet is in the most basic state, code reuse rate is low, low development efficiency, can not adapt to large-scale, complex web development requirements.
First, to implement event-driven, MVC technology must be used in jsp-servlet development.
M=model (model)
V=view (view)
C=control (Control)
View (V) defines the user interface. The model (M) defines abstract classes and logic. Control (C) is responsible for doing business processing based on the logic of the event invocation model that occurs in the view.
So so
Model is implemented by ordinary Java classes.
The view is implemented by the JSP.
Control is implemented by the servlet.
Views and models are closely related and independent of each other.
A model is an abstraction of a view and must contain some logic to handle the events of the objects represented by the view.
At the same time, views can be expressed in a variety of ways for the same logic.
For example, in web development,
[1] For a singleselection class that represents a "radio" abstraction, it can be displayed as a radio button on the user's browser, a radio drop-down box, or any other control of a single selection nature.
[2] for a submition class that represents a "submit" abstraction, it can be displayed as a Submit button on a user's browser, a hyperlink, a picture, or even any control that triggers a JavaScript-capable submit () method.
Event-driven is extremely important for MVC technology and is implemented primarily by control. The Jsp-servlet implementation itself is ideal for writing event-driven programs.
As we all know, the Javax.servlet.http.HttpServlet class calls every
DoPost (httpservletrequest req, HttpServletResponse resp)
Or
Doget (httpservletrequest req, HttpServletResponse resp)
method to respond to a client's submit operation.
The event that the servlet responds to is the client browser's submit operation. The client browser's submit event triggers a specific event-handling method for the servlet, but there is only one entry: the service of the Javax.servlet.http.HttpServlet class (HttpServletRequest req, HttpServletResponse resp) method. (Specific to the response to the operation of the client, it may be dopost (httpservletrequest req, HttpServletResponse resp) or doget (HttpServletRequest req, HttpServletResponse resp) method.
So you can override these methods to control how the servlet responds to a submit event, calling a different Jsp,java BEAN, or even an EJB.
Example: Eventdrivenservlet inherits Javax.servlet.http.HttpServlet, and overrides Dopost (HttpServletRequest req, HttpServletResponse resp) and Doget (HttpServletRequest req, HttpServletResponse resp) method, so that all 2 methods directly call the same method, we named this method "Act"??
void Act (httpservletrequest req, HttpServletResponse resp)