JavaWeb创建项目(非Maven)
模拟登录(不要求连接数据库[按需])
登录成功跳转其他页面即可
package com.hp.test;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet(“/test”)
public class TestServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String username = req.getParameter(“username”);
String password = req.getParameter(“password”);
if (username.equals(“root”) && password.equals(“root”)){
req.getRequestDispatcher(“test”).forward(req,resp);
}else {
resp.setContentType(“text/html;charset=utf-8”);
PrintWriter out = resp.getWriter();
out.write(“
}
}
}
<%--
Created by IntelliJ IDEA.
User: 慕
Date: 2022/7/25
Time: 9:18
To change this template use File | Settings | File Templates.
–%>
<%@ page contentType=“text/html;charset=UTF-8” language=“java” %>
| 账号 | |
| 密码 | |
二、创建Maven项目
模拟登录(不要求连接数据库[按需])
登录成功跳转其他页面即可
(不会)



