Separation of front and back ends of vue and servlet (review)

1. Vue review

1. Steps to use vue:

(1) Import vue.js
(2) Create the largest div tag except body, given the id value
(3) Create a vue object

 new Vue({
    
    
           el:"#app",
           data:{
    
    }//定义变量
           methods:{
    
    } //定义方法

2. Vue syntax:

v-bind:value(:value),v-model:value="",v-if,v-show,
v-for的使用及用途
  {
   
   {}}插值表达式
1、v-bind单项数据绑定 
<input v-bind:value= "***">
2、v-model双向数据绑定 
<input v-model= "***">
同步更改data里面的***值(只能运用在表单元素中) 
3、v-model相当于value的效果

Two, servlet and tomcat

Servlet is a java program, a Java class that can receive HTTP requests , so HTTP requests need to be implemented. There is a class javax.servlet.http.HttpServlet
in the JavaEE library that implements the HTTP protocol. The class we create only needs to inherit this HttpServlet class. The HTTP protocol is implemented and HTTP requests can be accepted

Create a class that inherits javax.servlet.http.HttpServlet
and inherit HttpServlet to be able to receive HTTP requests. We call such a class a Servlet class, similar to ***Servlet format named
in the Servlet class we created, and rewrite doPost /doGet is used to handle different user requests

servlet configuration

Add the @WebServlet annotation to the created Servlet class, configure the url in the parameter after the annotation, and the url must also start with /

//每一个类,继承HttpServlet,该类就是一个Servlet,每一个servlet都有一个访问路径
@WebServlet("/deptC")
public class DeptC extends HttpServlet {
    
    
    //引入service层
    private IDeptService deptService=new DeptServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    
    
        System.out.println("测试访问doget...");
        var list = deptService.list();
        System.out.println(list);
        //数据转化成json格式,再响应给游览器
        JsonUtil.transJson(list,resp);
    }

insert image description here
insert image description here

tomcat configuration
![](https://img-blog.csdnimg.cn/8fbacb8233c946b494d8248dcf8e9b79.png

The process of Tomcat responding to user requests is as follows:

1. The user sends an HTTP request to Tomcat (web server) through the browser.
2. After Tomcat receives the request, it sends the request information to the Servlet container, and gives the servlet container a request object and a response object.
3. The Servlet container loads the Servlet, and first creates a Servlet instance. Then tell the servlet instance to say: Hey! Boy, I have a user request object and response object here, you can handle it.
4. The Servlet instance obtains the client's request information from the request object, and then performs corresponding processing.
5. The Servlet instance hands over the processing result to the response object and sends it to the client through the response object.
insert image description here
Note:
Request object: HttpServletRequest
Response object: HttpServletResponse

Guess you like

Origin blog.csdn.net/2201_75506216/article/details/131688497