关于Response.redirect()方法

1. sendRedirect 后面要加上return。
2. sendRedirect 执行过程是先转向还是先执行后续代码再转向?
答: 先执行代码再转向,在一个sendRedirect后面不能再有其他向页面中写入的操作。

3. 关于在redirect中相对地址的写法:

在servlet中配置的Servlet请求URL为:
/test/servlet/TestRediect
请求URL
test/servlet/TestRediect
转向URL
/rediectPage.jsp : http://localhost:8080/rediectPage.jsp
./rediectPage.jsp : http://localhost:8080/webtest2/test/servlet/rediectPage.jsp
../rediectPage.jsp : http://localhost:8080/webtest2/test/rediectPage.jsp
.../rediectPage.jsp : http://localhost:8080/webtest2/test/servlet/.../rediectPage.jsp
使用点转向页面注意:
一个点相当于请求URL中去掉最底一层的URL/
两个点相当于请求URL中去掉最底两层的url/

最好使用:
/webtest2/rediectPage.jsp : http://localhost:8080/webtest2/rediectPage.jsp

原文地址:https://www.cnblogs.com/caiyao/p/4035227.html