页面从http://localhost:8080自动跳转到指定页面(之前的Web日历)

编程入门 行业动态 更新时间:2024-10-10 12:20:23

<a href=https://www.elefans.com/category/jswz/34/1771336.html style=页面从http://localhost:8080自动跳转到指定页面(之前的Web日历)"/>

页面从http://localhost:8080自动跳转到指定页面(之前的Web日历)

注意不要把地址写成main.jsp了,这时还没有携带数据呢,写sevlet中的main


index.jsp

<%--Created by IntelliJ IDEA.User: U100926Date: 2021/12/29Time: 17:41To 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 {@Overrideprotected 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: U100926Date: 2021/12/30Time: 10:16To 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: U100926Date: 2021/12/30Time: 10:20To 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日历)

本文发布于:2024-03-14 22:07:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1737441.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:页面   跳转到   日历   http   Web

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!