页面从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日历)
发布评论