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

本文展示了如何使用JavaScript在JSP页面中实现按钮点击事件触发页面跳转。在index.jsp中,通过设置按钮的onclick属性,当用户点击'注册VIP'按钮时,页面将重定向至register.jsp进行注册操作。register.jsp为一个包含注册表单的页面。
摘要由CSDN通过智能技术生成

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页面点击注册按钮就跳转到了注册的页面
在这里插入图片描述

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值