JSP三种页面跳转方式的比较 01 December 2009 0:51 Tuesday by 小屋 浏览(1405)

使用JSP大约有下列三种跳转方式:
1. response.sendRedirect();
2. response.setHeader("Location","");
3. <jsp:forward page="" />

经过试验得到下面的一些规则:

一. response.sendRedirect()

此语句前不允许有out.flush(),如果有,会有异常:

 

java.lang.IllegalStateException: Can't sendRedirect() after data has committed to the client.

 

at com.caucho.server.connection.AbstractHttpResponse.sendRedirect(AbstractHttpResponse.java:558)

 

...

阅读全文>>