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页面点击注册按钮就跳转到了注册的页面

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

被折叠的 条评论
为什么被折叠?



