<JAVA EE>页面跳转

本文介绍了几种常见的网页跳转技术,包括使用HTML元标签实现定时跳转、利用JavaScript进行即时和定时跳转,以及通过JSP请求转发实现页面跳转的方法。这些技术广泛应用于网站导航和用户体验优化中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

web页面跳转记录

html:

<head>
    <!-- 以下方式定时转到其他页面 -->
    <!-- content 中的 0 表示刷新时间 -->
    <meta http-equiv="refresh" content="0;url=hello.html"> 
</head>

js:

<script language="javascript" type="text/javascript"> 
// 以下方式直接跳转
window.location.href='hello.html';
// 以下方式定时跳转
setTimeout("javascript:location.href='hello.html'", 5000); 
</script>

jsp

request.getRequestDispatcher("/webpage/message.jsp").forward(request,response);
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>xx市地理可视化系统</title> <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css"> <style> body { background-color: #f5f5f5; font-family: 'KaiTi', '楷体', serif; } .login-box { width: 400px; margin: 100px auto; padding: 30px; background: white; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); } .title { text-align: center; margin-bottom: 25px; color: #3498db; font-weight: bold; font-size: 24px; } .captcha-box { display: flex; align-items: center; margin: 15px 0; } .captcha { font-size: 18px; letter-spacing: 3px; color: #e74c3c; font-weight: bold; margin-left: 10px; user-select: none; } </style> </head> <body> <div class="login-box"> <div class="title">恩施市地理可视化系统</div> <form id="loginForm"> <div class="mb-3"> <label for="username" class="form-label">用户名</label> <input type="text" class="form-control" id="username" required> <div class="invalid-feedback">用户名不能为纯数字</div> </div> <div class="mb-3"> <label for="password" class="form-label">密码</label> <input type="password" class="form-control" id="password" required> <div class="invalid-feedback">密码长度至少4位</div> </div> <div class="captcha-box"> <input type="text" class="form-control" id="captchaInput" placeholder="输入验证码" required> <div class="captcha" id="captcha"></div> </div> <div class="d-grid gap-2 mt-4"> <button type="submit" class="btn btn-primary"><i class="bi bi-box-arrow-in-right"></i> 登录</button> <button type="button" class="btn btn-outline-secondary" onclick="window.location.href='registration.html'"><i class="bi bi-person-plus"></i> 注册</button> </div> </form> </div> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script> <script> // 生成验证码 function generateCaptcha() { const chars = '0123456789ABCDEFGHJKLMNPQRSTUVWXYZ'; let captcha = ''; for (let i = 0; i < 5; i++) { captcha += chars.charAt(Math.floor(Math.random() * chars.length)); } document.getElementById('captcha').textContent = captcha; return captcha; } let currentCaptcha = generateCaptcha(); document.getElementById('loginForm').addEventListener('submit', function(e) { e.preventDefault(); // 获取表单数据 const username = document.getElementById('username').value; const password = document.getElementById('password').value; const captchaInput = document.getElementById('captchaInput').value; // 验证用户名不能为纯数字 if (/^\d+$/.test(username)) { alert('用户名不能为纯数字'); return; } // 验证密码长度至少6位 if (password.length < 4) { alert('密码长度至少4位'); return; } // 验证验证码 if (captchaInput !== document.getElementById('captcha').textContent) { alert('验证码错误'); return; } // 显示加载动画 const submitBtn = document.querySelector('button[type="submit"]'); const originalBtnText = submitBtn.innerHTML; submitBtn.disabled = true; submitBtn.innerHTML = '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> 登录中...'; // 发送登录请求到json-server fetch('http://localhost:3000/users?username=' + username + '&password=' + password) .then(response => response.json()) .then(data => { if (data.length > 0) { // 登录成功,跳转到主页面并传递用户名 window.location.href = 'main.html?username=' + encodeURIComponent(username); } else { alert('用户名或密码错误'); submitBtn.disabled = false; submitBtn.innerHTML = originalBtnText; } }) .catch(error => { console.error('Error:', error); alert('登录失败,请稍后重试'); submitBtn.disabled = false; submitBtn.innerHTML = originalBtnText; }); }); </script> </body> </html>为什么注册请求成功后不能成功跳转回login.html
06-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值