HTML 重定向 页面跳转

通过响应头重定向

响应状态 301 和 302 可以指定重定向URL, 推荐使用302 FOUND

HttpServletResponse. static final int SC_MOVED_TEMPORARILY
状态代码(302),指示资源已临时移动到另一个位置,但未来的引用仍应使用原始URI来访问资源。 保留此定义是为了向后兼容。 SC_FOUND现在是首选定义。

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<%
    /* 重定位状态分两种:
        永久301 Moved Permanently和暂时302 Found
        谨慎使用永久转移
    */
    //response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
    response.setStatus(HttpServletResponse.SC_FOUND);
    response.setHeader("Location", "indexs.jsp");
%>

通过元数据 meta 跳转页面

<!DOCTYPE HTML>
<html lang="zh">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<!-- 3秒后跳转页面 -->
<meta http-equiv="refresh" content="2;url='https://www.google.com'">

<title>3秒后进入主题</title>
<link rel="icon" href="icon/icon.ico">
<link rel="stylesheet" href="css/global.css">

<body>
    <p style="text-align: center;">
        <a href="https://www.google.com">点击立即进入</a>
    </p>
</body>
</html>

猜你喜欢

转载自www.cnblogs.com/develon/p/10706320.html
今日推荐