JSP应用技巧:实现三种页面跳转方式的对比
发布时间:2023-05-25 13:21:12 所属栏目:教程 来源:
导读:使用jsp大约有下列三种跳转方式:
1. response.sendredirect();
2. response.setheader("location","");
3. <jsp:forward page="" />
经过试验得到下面的一些规则:
一. response.sendredirect(
1. response.sendredirect();
2. response.setheader("location","");
3. <jsp:forward page="" />
经过试验得到下面的一些规则:
一. response.sendredirect(
使用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) ... 跳转后浏览器地址栏变化 如果要跳到不同主机下,跳转后,此语句后面的语句会继续执行,如同新开了线程,但是对response的操作已经无意义了; 如果要跳到相同主机下,此语句后面的语句执行完成后才会跳转; 二. response.setheader("location","") 此语句前不允许有out.flush(),如果有,页面不会跳转。 跳转后浏览器地址栏变化 此语句后面的语句执行完成后才会跳转 三. <jsp:forward page="" /> 此语句前不允许有out.flush(),如果有,会有异常: java.lang.illegalstateexception: forward() not allowed after buffer has committed. at com.caucho.server.webapp.requestdispatcherimpl.forward(requestdispatcherimpl.java:134) at com.caucho.server.webapp.requestdispatcherimpl.forward(requestdispatcherimpl.java:101) at com.caucho.jsp.pagecontextimpl.forward(pagecontextimpl.java:836) ... (编辑:聊城站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
站长推荐