Source code analysis of medical projects (1)

Take over the project on January 22

The project is a medical project;

The core points of the project:

Servlet usage process:

1. There are three methods in the GenericServlet class, which are the core methods;

init();

services(ServletRequestServletResponse);

destroy();

Then HttpServlet inherits GenericServlet, in addition to these three methods, there are two main methods, namely doPost(HttpServletRequest,HttpServiceResponse) and doGet( HttpServletRequest,HttpServiceResponse );

BaseServlet is the base class of our servlet, as an abstract class, it inherits HttpServlet;

The method of service is as follows:

	protected synchronized void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("content-type", "text/html;charset=UTF-8");
		this.request = request;
		this.response = response;
		setHandlePermission();

		logger.trace("The client initiates a request, the request object: " + this.getClass().getSimpleName());
		//View upload information
		for (Enumeration<String> e = request.getParameterNames(); e.hasMoreElements(); ) {
			String name = e.nextElement();
			//Comment input parameter print clq_0412
			//logger.trace("name:{} value:{}", name, request.getParameter(name));
		}

		session = request.getSession();

		employee = (Employee) session.getAttribute(Constant.sessionUserAttrib);
		writer = response.getWriter();
		//get parameter data
		dataJson = getParam(request);

		handle();
	}
Where employee is the user of the login operation, if the user is empty, the login page will be returned;

/**
     * Set the corresponding operation permission. Inherited classes must implement this method.
     */
    protected abstract void setHandlePermission();

(The method of setting permissions, when inheriting the BaseServlet abstract base class, the subclass must implement its abstract method)

2. PrintWriter writer = response.getWriter();

write as the object that returns to the foreground;

Using the write.print(Object o) inside, the data can be stored in the Object; the front end receives the data and uses it to display the page;

3.

protected void queryAll() {
	}
	protected void delete() {
	}
	protected void update() {
	}
	protected void query() {
	}
	protected void add() {
	}
There are four methods of adding, deleting, modifying and checking, plus all methods of one query. The background decides which method to call according to the controlType type of the front end;

4. Write a servlet and add @WebServlet("/xxx.do") above the class by using annotations;

Implement the method of adding, deleting, modifying and checking; it is equivalent to making an interface, and the foreground calls to obtain data;

The core of the background interaction is this. In the next article, I will write the file analysis of the mapping core between entity classes and databases;




Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326712322&siteId=291194637