我是靠谱客的博主 含糊草丛,这篇文章主要介绍页面从http://localhost:8080自动跳转到指定页面(之前的Web日历),现在分享给大家,希望可以做个参考。

注意不要把地址写成main.jsp了,这时还没有携带数据呢,写sevlet中的main
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

index.jsp

<%--
  Created by IntelliJ IDEA.
  User: U100926
  Date: 2021/12/29
  Time: 17:41
  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>

<!-- 运行javaScript不用额外安装包,自带了 -->
<script>window.location.href='main';</script>

<!--方法1-->
<!--2种写法都可以,单双引号都可以,注意不要写成了main.jsp会报空指针异常,此时jsp页面还没有携带参数!要写servlet在地址栏的映射main,如下
@WebServlet("/main")
public class Main extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {.......}
<script>window.location.href='main';</script>
<script>window.location.href="main";</script>
<script>window.location.href='http://localhost:8080/main';</script>
<script>window.location.href='success.jsp';</script>
 -->

<!--方法2-->
<!--
<script>setTimeout("location.href='main'", 0);</script>
<script>setTimeout("location.href='error.jsp'", 0);</script>
-->

</body>
</html>

测试用的2个页面

success.jsp

<%--
  Created by IntelliJ IDEA.
  User: U100926
  Date: 2021/12/30
  Time: 10:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>success</title>
</head>
<body>
jump success
</body>
</html>

error.jsp

<%--
  Created by IntelliJ IDEA.
  User: U100926
  Date: 2021/12/30
  Time: 10:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>error</title>
</head>
<body>
jump error
</body>
</html>

最后

以上就是含糊草丛最近收集整理的关于页面从http://localhost:8080自动跳转到指定页面(之前的Web日历)的全部内容,更多相关页面从http://localhost:8080自动跳转到指定页面(之前内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(89)

评论列表共有 0 条评论

立即
投稿
返回
顶部