一、前端发送请求,后端后端响应
1、前期准备需要导入的架包,如图下所示:
2、具体的实现
使用a标签发送test地址请求
web代码如下:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>主页</title>
</head>
<body>
<h3><a href="test" >请求跳转</a></h3>
</body>
</html>
当点击a标签发送请求,后端处理test地址请求对应的操作
servlet层代码如下:
package com.dou.servlet;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
@WebServlet("/test")
public class Test01 extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("test01...doget");
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("test01...dopost");
}
}
运行效果如下:
当点击请求跳转a标签的时候,后端做出响应
duGet方法执行