JSP--从一个jsp页面通过按钮跳转到另一个jsp页面

JSP按钮跳转页面的方法

一句代码实现jsp页面跳转!

在初始的index.jsp页面中,给按钮添加一个点击事件(onclick)

οnclick="window.location.href=‘register.jsp’;"

通过单引号引住的部分是我们要跳转到的那个jsp页面

<%--
  Created by IntelliJ IDEA.
  User: 杨小冥
  Date: 2020/11/11
  Time: 18:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
    <form action="/login" method="post">
      账号<input type="text" name="username"/><br>
      密码<input type="password" name="password"/><br>
      <input type="submit" value="登录"/>
    </form>
    <input type="button" onclick="window.location.href='register.jsp';" value="注册VIP">
  </body>
</html>

在这里插入图片描述
还有一个注册页面(register.jsp)

<%--
  Created by IntelliJ IDEA.
  User: 杨小冥
  Date: 2020/11/11
  Time: 18:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>register</title>
</head>
<body>
    <h1>欢迎注册xxxVIP</h1>
    <form action="/toregister" method="post">
        账号<input type="text" name="username"/><br>
        密码<input type="password" name="password"/><br>
        <input type="submit" value="注册"/>
    </form>
</body>
</html>

在index页面点击注册按钮就跳转到了注册的页面
在这里插入图片描述


版权声明:本文为yxmoar原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。