11月29日学习日志

今天学习了jsp的页面重定向。

当需要将文档移动到一个新的位置时,就需要使用JSP重定向了。

最简单的重定向方式就是使用response对象的sendRedirect()方法。这个方法的签名如下:

public void response.sendRedirect(String location)
throws IOException 

实例:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.*" %>
<html>
<html>
<head>
<title>页面重定向</title>
</head>
<body>

<h1>页面重定向</h1>

<%
   // 重定向到新地址
   String site = new String("http://www.runoob.com");
   response.setStatus(response.SC_MOVED_TEMPORARILY);
   response.setHeader("Location", site); 
%>

</body>
</html>

 

posted @ 2020-11-29 18:04  张笑天  阅读(51)  评论(0编辑  收藏  举报