<c:redirect>重定向标签
相当于HttpServletResponse的sendRedirect()方法。
<%@page contentType="text/html" pageEncoding="UTF-8" %><%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %><!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Hello</title></head><body> <c:redirect url="/home.jsp"> <c:param name="name" value="${param.name}"></c:param> <c:param name="age" value="${param.age}"></c:param> </c:redirect></body></html>
index.jsp
<%@ page contentType="text/html" pageEncoding="UTF-8" %><!DOCTYPE html><html><head> <title>Home</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body> 欢迎 ${param.name} 登陆</body></html>
home.jsp
测试:http://127.0.0.1/home.jsp?name=zs&age=18
响应:欢迎 zs 登陆
<c:url>URL重写标签
在用户关闭Cookie功能时,自动用Session ID来进行URL重写。