当前位置: 技术问答>java相关
重定向是发生的问题。response.sendRedirect()
来源: 互联网 发布时间:2015-06-20
本文导语: 我的一个JSP文件中有这样一条语句: response.sendRedirect("rmailerror.jsp"); 在有的JSP中可以执行,有的JSP中就出现这样的错误提示: type Exception report message Internal Server Error description The server encountered an internal error...
我的一个JSP文件中有这样一条语句:
response.sendRedirect("rmailerror.jsp");
在有的JSP中可以执行,有的JSP中就出现这样的错误提示:
type Exception report
message Internal Server Error
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
java.lang.IllegalStateException: Cannot forward after response has been committed
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:367)
重点是这里:(Cannot forward after response has been committed)
为什么 response 会被禁止呢???
response.sendRedirect("rmailerror.jsp");
在有的JSP中可以执行,有的JSP中就出现这样的错误提示:
type Exception report
message Internal Server Error
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
java.lang.IllegalStateException: Cannot forward after response has been committed
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:367)
重点是这里:(Cannot forward after response has been committed)
为什么 response 会被禁止呢???
|
可以用下面的函数实现之,无此限制
-1)
{
wsStr=new wsString();
String[] url_a=wsStr.split(url,"|");
url_t=url_a[1];
url_lnk=url_a[0];
}
else
{
url_t="0";
url_lnk=url;
}
String tmp="";
return tmp;
}
%>
-1)
{
wsStr=new wsString();
String[] url_a=wsStr.split(url,"|");
url_t=url_a[1];
url_lnk=url_a[0];
}
else
{
url_t="0";
url_lnk=url;
}
String tmp="";
return tmp;
}
%>
|
response.sendRedirect是通过设置http头来实现的,如果你已经输出网页的一部分了,就不能设置http头。
这与jsp引擎的实现有关。如果它是对输出进行缓存,最后才输出,那么就可以设置http头,否则哪怕你只输出了一个字符,也不能再设置http头了。
另一个指令flush也与此有关。
这与jsp引擎的实现有关。如果它是对输出进行缓存,最后才输出,那么就可以设置http头,否则哪怕你只输出了一个字符,也不能再设置http头了。
另一个指令flush也与此有关。
|
http://www.csdn.net/expert/topic/791/791072.xml?temp=.6192896
package walksing.string;
import java.text.*;
import java.util.*;
public class wsString
{
/***$id added by WalkSing [wcsz@mail.china.com] 2003-03-22 9:57 ***/
public String Jreplace(String S,String T,String I)
{ /*$id:walksing walksing@163.com 2002-03-12 9:57 make.
*para S --Source String will find to be replaced String,which will be overwrite with T;
*para T --Target String which will overwrite S;
*para I --Input String from which to find;
*return String replacement Result;
*note:S,T,I can be String Type;
*ver 1.0;
*/
if (I.length()
package walksing.string;
import java.text.*;
import java.util.*;
public class wsString
{
/***$id added by WalkSing [wcsz@mail.china.com] 2003-03-22 9:57 ***/
public String Jreplace(String S,String T,String I)
{ /*$id:walksing walksing@163.com 2002-03-12 9:57 make.
*para S --Source String will find to be replaced String,which will be overwrite with T;
*para T --Target String which will overwrite S;
*para I --Input String from which to find;
*return String replacement Result;
*note:S,T,I can be String Type;
*ver 1.0;
*/
if (I.length()