项目结构:
创建RequestTest。作用:获取表单的内容(从前端反馈到后端)
package com.Li.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class RequestTest extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("进入了RequestTest");
String username = req.getParameter("username");
String password = req.getParameter("password");
System.out.println(username+" "+password);
resp.sendRedirect("/r/Success.jsp");//获取完信息之后重定向,指向下一个jsp
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
}
index.jsp(前端的内容)
Hello World!
<%--${pageContext.request.contextPath}代表当前项目--%>
重定向:
<%--
Created by IntelliJ IDEA.
User: Li
Date: 2022/6/6
Time: 19:09
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
Title
Success!
配置web忽略。太基础了。
效果:



