2021.05.24 JSP登陆跳转功能的实现

本文详细介绍了如何在2021年05月24日实现JSP的登录跳转功能,包括主页面、判断逻辑和欢迎页面的代码示例。
摘要由CSDN通过智能技术生成

代码(主页面)

<%--
  Created by IntelliJ IDEA.
  User: john
  Date: 2021/5/24
  Time: 11:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
    <title>主页面</title>
</head>
<body>
<form action="controls_login.jsp" method="post">
    用户名: <input type="text" name="username">
    <br>&nbsp;&nbsp;&nbsp;码: <input type="password" name="password">
    <br>
    <input type="submit">
</form>
</body>
</html>

在这里插入图片描述

代码(判断)

<%--
  Created by IntelliJ IDEA.
  User: john
  Date: 2021/5/24
  Time: 11:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>判断页</title>
</head>
<body>
<%
    String username = request.getParameter("username");
    String password = request.getParameter("password");


    if (username.equals("root") && password.equals("root0730")){
        RequestDispatcher rd = request.getRequestDispatcher("we.jsp");
        rd.forward(request,response);
    }
    else{
        response.sendRedirect("login.jsp");
    }
%>
</body>
</html>

代码(欢迎页)

<%--
  Created by IntelliJ IDEA.
  User: john
  Date: 2021/5/24
  Time: 11:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>欢迎页</title>
</head>
<body>
<%
    String name = request.getParameter("username");
    out.print("欢迎你"+name);
%>
</body>
</html>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值