温馨提示:您的每一次转载,体现了我写此文的意义!!!烦请您在转载时注明出处http://www.blogjava.net/sxyx2008/谢谢合作!!!

java.lang.illegalstateexception异常解决 -凯发k8网页登录

温馨提示:您的每一次转载,体现了我写此文的意义!!!烦请您在转载时注明出处http://www.blogjava.net/sxyx2008/谢谢合作!!!

最近在调试xwiki的时候遇到java.lang.illegalstateexception异常,在google上baidu了一把
经过分析查看jdk文档终于找到了凯发天生赢家一触即发官网的解决方案,在response.sendredirect("")方法后加return语句即可:
原因是在程序中两次调用response.sendredirect("")方法

j2ee5.0中的介绍:

sendredirect

void sendredirect(java.lang.string location)
throws java.io.ioexception
sends a temporary redirect response to the client using the specified redirect location url. this method can accept relative urls; the servlet container must convert the relative url to an absolute url before sending the response to the client. if the location is relative without a leading '/' the container interprets it as relative to the current request uri. if the location is relative with a leading '/' the container interprets it as relative to the servlet container root.

if the response has already been committed, this method throws an illegalstateexception. after using this method, the response should be considered to be committed and should not be written to.

 

parameters:
location - the redirect location url
throws:
java.io.ioexception - if an input or output exception occurs
java.lang.illegalstateexception - if the response was committed or if a partial url is given and cannot be converted into a valid url
posted on 2010-01-26 10:18 雪山飞鹄 阅读(147329) 评论(12)     所属分类: javase
# re: java.lang.illegalstateexception异常解决... 2010-10-25 16:38
呵呵,不错!  回复  
  

# re: java.lang.illegalstateexception异常解决... 2010-10-25 16:39
illegalcomponentstateexception
在不合理或不正确时间内唤醒一方法时出现的异常信息。换句话说,即 java 环境或 java 应用不满足请求操作。  回复  
  

# re: java.lang.illegalstateexception异常解决 2010-12-29 16:19
请不要粘来粘去好不好 都在很多地方看到了这一个说法  回复  
  

# re: java.lang.illegalstateexception异常解决 2011-01-07 16:22
在response.sendredirect()方法后加return语句即可,如下:
response.sendredirect("index.jsp");
return;

原因是:在程序中两次调用了response.sendredirect()方法。

jdk5.0文档中很清楚地介绍了出现illegalstateexception异常的可能情况:

1)同一个页面中再次调用response.sendredirect()方法。
2)提交的url错误,即不是个有效的url。

  回复  
  

# re: java.lang.illegalstateexception异常解决 2011-03-29 13:12
public modelandview downloadprint(httpservletrequest request,httpservletresponse response, databaseform databaseform) {
hashmap model = new hashmap();
try {
//string doc_nme = (string) request.getparameter("doc_nme");
//string bfr_nme = (string) request.getparameter("bfr_nme");
response.setcontenttype("text/html");
javax.servlet.servletoutputstream out = response.getoutputstream();
// 取得文件在服务器上的文件路径
string filepatch = getservletcontext().getrealpath("");//获得编译后的文件路径
string allpathstr = filepatch "//applets//jre-1_5_0_18-windows-i586-p.rar" ;
file file = new file(allpathstr);
// 读取文件流
fileinputstream fileinputstream = new fileinputstream(file);
string bfr_nme = "jre-1_5_0_18-windows-i586-p.rar";//this.getdatabasemgr().querybfruserdocnm(doc_nme);
// 下载文件
// 设置响应头和下载保存的文件名
response.setcontenttype("application/x-msdownload");
response.setheader("content-disposition", "attachment; filename=" new string(bfr_nme.getbytes("gb2312"),"iso8859-1") "");
if (fileinputstream != null) {
int filelen = fileinputstream.available();
// 文件太大时内存不能一次读出,要循环
byte a[] = new byte[filelen];
fileinputstream.read(a);
out.write(a);
}
fileinputstream.close();
out.close();
return null;
//return new modelandview("downloadview", model);
} catch (exception e) {
e.printstacktrace();
model.put("errorinfo", e.getmessage());
return new modelandview("errorview", model);
}
}
  回复  
  

# re: java.lang.illegalstateexception异常解决[未登录] 2012-06-05 16:04
但是我整个文档里就没有那个response.sendredirect()语句啊,也有这个异常啊,大侠给看看:
<%
string filename = "d:/program files/genuitec/workspaces/zoology/webroot/jianfang.txt";
//if (request.getattribute("url") != null) {
// filename = (string)request.getattribute("url");
//}

system.out.print("filename " filename);
response.setcontenttype("application/msword");
response.setheader("content-disposition", "inline; filename="
filename);
bufferedinputstream bis = null;
bufferedoutputstream bos = null;
try {
bis = new bufferedinputstream(new fileinputstream(new file(filename)));
//getservletcontext().getrealpath("" filename)));
bos = new bufferedoutputstream(response.getoutputstream());
byte[] buff = new byte[2048];
char[] c =new char[2048];
int bytesread;
while (-1 != (bytesread = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesread);
}

} catch (final ioexception e) {
system.out.println("出现ioexception." e);
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}
%>  回复  
  

# re: java.lang.illegalstateexception异常解决 2012-06-07 11:26
我只是增加一个文件,为什么也报这个错误呢  回复  
  

# re: java.lang.illegalstateexception异常解决[未登录] 2012-06-30 09:39
现在关键的是,我的项目使用struts2写的,response.sendredirect()都是在struts2框架里面定义了的,我怎么处理呢?  回复  
  

# re: java.lang.illegalstateexception异常解决[未登录] 2012-12-01 18:16
java.lang.illegalstateexception
at org.apache.catalina.connector.responsefacade.sendredirect(responsefacade.java:435)
at org.apache.taglibs.standard.tag.common.core.redirectsupport.doendtag(redirectsupport.java:119)
at org.apache.jsp.movieshopping_jsp._jspx_meth_c_005fredirect_005f0(movieshopping_jsp.java:686)
at org.apache.jsp.movieshopping_jsp._jspx_meth_c_005fif_005f2(movieshopping_jsp.java:654)
at org.apache.jsp.movieshopping_jsp._jspservice(movieshopping_jsp.java:369)
at org.apache.jasper.runtime.httpjspbase.service(httpjspbase.java:70)
at javax.servlet.http.httpservlet.service(httpservlet.java:717)
at org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:374)
at org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:342)
at org.apache.jasper.servlet.jspservlet.service(jspservlet.java:267)
at javax.servlet.http.httpservlet.service(httpservlet.java:717)
at org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:290)
at org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206)
at org.apache.catalina.core.applicationdispatcher.invoke(applicationdispatcher.java:646)
at org.apache.catalina.core.applicationdispatcher.processrequest(applicationdispatcher.java:436)
at org.apache.catalina.core.applicationdispatcher.doforward(applicationdispatcher.java:374)
at org.apache.catalina.core.applicationdispatcher.forward(applicationdispatcher.java:302)
at org.apache.struts.chain.commands.servlet.performforward.handleasforward(performforward.java:113)
at org.apache.struts.chain.commands.servlet.performforward.perform(performforward.java:96)
at org.apache.struts.chain.commands.abstractperformforward.execute(abstractperformforward.java:54)
at org.apache.struts.chain.commands.actioncommandbase.execute(actioncommandbase.java:51)
at org.apache.commons.chain.impl.chainbase.execute(chainbase.java:190)
at org.apache.commons.chain.generic.lookupcommand.execute(lookupcommand.java:304)
at org.apache.commons.chain.impl.chainbase.execute(chainbase.java:190)
at org.apache.struts.chain.composablerequestprocessor.process(composablerequestprocessor.java:283)
at org.apache.struts.action.actionservlet.process(actionservlet.java:1913)
at org.apache.struts.action.actionservlet.doget(actionservlet.java:449)
at javax.servlet.http.httpservlet.service(httpservlet.java:617)
at javax.servlet.http.httpservlet.service(httpservlet.java:717)
at org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:290)
at org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206)
at org.springframework.web.filter.characterencodingfilter.dofilterinternal(characterencodingfilter.java:88)
at org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:76)
at org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:235)
at org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206)
at org.springframework.orm.hibernate3.support.opensessioninviewfilter.dofilterinternal(opensessioninviewfilter.java:198)
at org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:76)
at org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:235)
at org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206)
at org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:233)
at org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:191)
at org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:128)
at org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:102)
at org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:109)
at org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:293)
at org.apache.coyote.http11.http11processor.process(http11processor.java:849)
at org.apache.coyote.http11.http11protocol$http11connectionhandler.process(http11protocol.java:583)
at org.apache.tomcat.util.net.jioendpoint$worker.run(jioendpoint.java:454)
at java.lang.thread.run(thread.java:619)  回复  
  

# re: java.lang.illegalstateexception异常解决 2013-01-21 22:01

java.lang.illegalstateexception
at org.apache.catalina.connector.responsefacade.senderror(responsefacade.java:407)
at com.dyjy.mybook.web.action.bookaction.service(bookaction.java:65)
at javax.servlet.http.httpservlet.service(httpservlet.java:717)
at org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:290)
at org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206)
at org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:233)
at org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:191)
at org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:127)
at org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:103)
at org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:109)
at org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:293)
at org.apache.coyote.http11.http11processor.process(http11processor.java:861)
at org.apache.coyote.http11.http11protocol$http11connectionhandler.process(http11protocol.java:606)
at org.apache.tomcat.util.net.jioendpoint$worker.run(jioendpoint.java:489)
at java.lang.thread.run(thread.java:619)
2013-1-21 22:00:34 org.apache.catalina.core.standardwrappervalve invoke
严重: servlet.service() for servlet bookaction threw exception
java.lang.illegalstateexception
at org.apache.catalina.connector.responsefacade.sendredirect(responsefacade.java:435)
at com.dyjy.mybook.web.action.bookaction.service(bookaction.java:74)
at javax.servlet.http.httpservlet.service(httpservlet.java:717)
at org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:290)
at org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206)
at org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:233)
at org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:191)
at org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:127)
at org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:103)
at org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:109)
at org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:293)
at org.apache.coyote.http11.http11processor.process(http11processor.java:861)
at org.apache.coyote.http11.http11protocol$http11connectionhandler.process(http11protocol.java:606)
at org.apache.tomcat.util.net.jioendpoint$worker.run(jioendpoint.java:489)
at java.lang.thread.run(thread.java:619)
  回复  
  

# re: java.lang.illegalstateexception异常解决 2013-06-06 09:13
@yk
程序员通病—复制粘贴  回复  
  

# re: java.lang.illegalstateexception异常解决 2015-08-15 09:48
@lucky 你的问题解决了吗?怎么解决的?我也遇到相同的问题了。sturts2的
  回复  
  

网站地图