java.lang.IllegalStateException

jingshuai1029 2008-07-10 09:44:15

源程序的一部分, 写在servlet中:
public void logout(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException{
HttpSession session = request.getSession();
session.removeAttribute("username");
response.sendRedirect(request.getContextPath()+ "/admin/login.jsp");
}


上面程序当执行到最后一句时出现了问题,问题输出下面 求各位高手花一分钟时间看一下,在下先谢谢了。


java.lang.IllegalStateException
at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:435)
at com.js.servlet.adminUser.doPost(adminUser.java:32)
at com.js.servlet.adminUser.doGet(adminUser.java:21)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
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:175)
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:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
...全文
14235 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
奋斗者ing 2012-08-07
  • 打赏
  • 举报
回复
你加个return 看下,行吗。?
lingtiam 2011-11-24
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 qq979969786 的回复:]

还不行的一定是之前已经向浏览器输出了东西,比如我的本来是这样:
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String itemNo = req.getParameter("itemNo");
Item item……
[/Quote]
我加了return还是不行,然后照上面这个方法,把req.getRequestDispatcher()方法和resp.sendRedirect()方法调换了一下前后顺序就可以了。至于为什么会这样,还没搞懂
weiniyang 2011-11-19
  • 打赏
  • 举报
回复
我也解决啦!加return即可!
qq979969786 2011-08-21
  • 打赏
  • 举报
回复
还不行的一定是之前已经向浏览器输出了东西,比如我的本来是这样:
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String itemNo = req.getParameter("itemNo");
Item item = new ItemManagerImpl().findItemById(itemNo);
List itemCategoryList = DataDictManager.getInstance().getItemCategoryList();
List itemUnitList = DataDictManager.getInstance().getItemUnitList();
req.setAttribute("item", item);
req.setAttribute("itemCategoryList", itemCategoryList);
req.setAttribute("itemUnitList", itemUnitList);
req.getRequestDispatcher("/basedata/item_modify.jsp").forward(req, resp);

String commond = req.getParameter("commond");
if(!(commond == null && "".equals(commond)) && "modify".equals(commond)) {
Item itemModify = new Item();
itemModify.setItemNo(req.getParameter("itemNo"));
itemModify.setItemName(req.getParameter("itemName"));
itemModify.setPattern(req.getParameter("pattern"));
itemModify.setSpec(req.getParameter("spec"));

ItemCategory itemCategoryModify = new ItemCategory();
itemCategoryModify.setId(req.getParameter("category"));
itemModify.setItemCategory(itemCategoryModify);

ItemUnit itemUnitModify = new ItemUnit();
itemUnitModify.setId(req.getParameter("unit"));
itemModify.setItemUnit(itemUnitModify);

new ItemManagerImpl().modifyItem(itemModify);

resp.sendRedirect(req.getContextPath() + "/servlet/item/SercherItemServlet");
return;
}
}
改称这样就好了:
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String commond = req.getParameter("commond");
if(!(commond == null && "".equals(commond)) && "modify".equals(commond)) {
Item itemModify = new Item();
itemModify.setItemNo(req.getParameter("itemNo"));
itemModify.setItemName(req.getParameter("itemName"));
itemModify.setPattern(req.getParameter("pattern"));
itemModify.setSpec(req.getParameter("spec"));

ItemCategory itemCategoryModify = new ItemCategory();
itemCategoryModify.setId(req.getParameter("category"));
itemModify.setItemCategory(itemCategoryModify);

ItemUnit itemUnitModify = new ItemUnit();
itemUnitModify.setId(req.getParameter("unit"));
itemModify.setItemUnit(itemUnitModify);

new ItemManagerImpl().modifyItem(itemModify);

resp.sendRedirect(req.getContextPath() + "/servlet/item/SercherItemServlet");
return;
} else {
String itemNo = req.getParameter("itemNo");
Item item = new ItemManagerImpl().findItemById(itemNo);
List itemCategoryList = DataDictManager.getInstance().getItemCategoryList();
List itemUnitList = DataDictManager.getInstance().getItemUnitList();
req.setAttribute("item", item);
req.setAttribute("itemCategoryList", itemCategoryList);
req.setAttribute("itemUnitList", itemUnitList);
req.getRequestDispatcher("/basedata/item_modify.jsp").forward(req, resp);
}
}
Yuxiaoping132 2011-06-01
  • 打赏
  • 举报
回复
楼主,我的加了return 也还是一样不能解决哦,麻烦帮忙
轻灵 2011-04-26
  • 打赏
  • 举报
回复
经过分析、查看jdk文档终于找到解决的办法,在response.sendRedirect()方法后加return语句即可,如下:
response.sendRedirect("login.jsp");
return;
Ndk 2011-01-03
  • 打赏
  • 举报
回复
写一个 return 可以解决
javabenniao 2010-03-10
  • 打赏
  • 举报
回复
是写一个return 就可以吗?我的是return null; 可是他也报这个异常让我很郁闷
  • 打赏
  • 举报
回复
我也遇到这样的问题
guy_java 2009-09-15
  • 打赏
  • 举报
回复
找到解决问题的办法了吗?
我也遇到了,死活解决不了?
楼主怎么解决的快告诉我。
yuxin2009 2009-06-05
  • 打赏
  • 举报
回复
java.lang.IllegalStateException
「已注销」 2009-05-08
  • 打赏
  • 举报
回复
BS楼主
sagezk 2008-07-11
  • 打赏
  • 举报
回复
你 response.sendRedirect(request.getContextPath()+ "/admin/login.jsp"); 时响应已经被提交了,即响应信息已经开始发往客户端了,试试把缓存设大点大到 sendRedirect 前缓存还没第一次填满。
zhu20808301 2008-07-11
  • 打赏
  • 举报
回复
学习
jingshuai1029 2008-07-11
  • 打赏
  • 举报
回复
谢谢各位了,我很是感动大家能帮助我
xiaocaimaomao 2008-07-10
  • 打赏
  • 举报
回复
jdk5.0文档中很清楚地介绍了出现IllegalStateException异常的可能情况:

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

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
xiaocaimaomao 2008-07-10
  • 打赏
  • 举报
回复
java.lang.IllegalStateException
org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:423)

经过分析、查看jdk文档终于找到解决的办法,在response.sendRedirect()方法后加return语句即可,如下:
response.sendRedirect("login.jsp");
return;

原因是:在程序中两次调用了response.sendRedirect()方法。
xiaocaimaomao 2008-07-10
  • 打赏
  • 举报
回复
错在session.removeAttribute("username"); 你是想传递参数?该用session.setAttribute吧
mengweilil 2008-07-10
  • 打赏
  • 举报
回复
Google
高级搜索 | 使用偏好
所有网页 中文网页 简体中文网页 中国的网页
网页 约有111,000项符合java.lang.IllegalStateException 的查询结果,以下是第1-10项 (搜索用时 0.04 秒)
简单理解java.lang.IllegalStateException异常:简单分析和简单解决方案 ...
getOutputStream(); 抛出异常: ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception java.lang.IllegalStateException: ...
blog.csdn.net/patriotlml/archive/2007/05/28/1628556.aspx - 35k - 网页快照 - 类似网页
java.lang.IllegalStateException异常解决办法- 记录历史,展望未 ...
java.lang.IllegalStateException异常解决办法. ... java.lang.IllegalStateException - If the response was committed or if a partial URL is given and cannot be ...
blog.csdn.net/freedom119/archive/2007/08/31/1766851.aspx - 27k - 网页快照 - 类似网页
blog.csdn.net站内的其它相关信息 »
简单理解java.lang.IllegalStateException异常:简单分析和简单解决方案 ...
简单理解java.lang.IllegalStateException异常:简单分析和简单解决方案.
read.newbooks.com.cn/info/128444.html - 18k - 网页快照 - 类似网页
java.lang.IllegalStateException - thinktalk - BlogJava
re: java.lang.IllegalStateException 回复 更多评论 ... 谢谢; --sdu; 3. re: java.lang.IllegalStateException; 不能同时有两次的response.sendRedirect();; --sdf ...
www.blogjava.net/ThinkingTalking/archive/2007/08/22/114839.html - 36k - 网页快照 - 类似网页
错误:java.lang.IllegalStateException: must call load class ...
re: 错误:java.lang.IllegalStateException: must call load class on top 2007-06-26 11:04 BeanSoft. 我们还碰过过测试的时候启动weblogic 的账户和类库的jar 文件 ...
www.blogjava.net/sayyy/archive/2007/06/25/126104.html - 24k - 网页快照 - 类似网页
www.blogjava.net站内的其它相关信息 »
java.lang.IllegalStateException_百度知道
java.lang.IllegalStateException. 悬赏分:20 - 解决时间:2007-12-18 10:17 ... jspsmart下载异常:java.lang.IllegalStateException. ...
zhidao.baidu.com/question/41712434.html?fr=qrl3 - 22k - 网页快照 - 类似网页
高分求解:java.lang.IllegalStateException: getOutputStream() has ...
主题:高分求解:java.lang.IllegalStateException: getOutputStream() has already been called for this response 我用此类下载文件,下载正常但在日志中报如下错误, ...
book.77169.org/data/web5401/20050311/20050311__3814089.html - 11k - 网页快照 - 类似网页
有没有人遇到这种异常:java.lang.IllegalStateException: Function is ...
有没有人遇到这种异常:java.lang.IllegalStateException: Function is not supported?
www.javanb.com/eclipse/1/9800.html - 14k - 网页快照 - 类似网页
请教java.lang.IllegalStateException:getOutputStream()错误解决方法
2005年7月13日 ... java.lang.IllegalStateException: getOutputStream() has already been called for this response这个错误是怎么回事呢, 我在用bufferimputStream向 ...
dev2dev.bea.com.cn/bbs/thread.jspa?forumID=121&threadID=24496&messageID=143599 - 26k - 网页快照 - 类似网页
请问jspSmartUpload报错为“java.lang.IllegalStateException ”是什么意思?
主要解答:sanda; 感谢:sanda; 审核者:xmvigour. 请问jspSmartUpload报错为“java.lang.IllegalStateException ”是什么意思? ...
book.chinaz.com/FAQ/jsp/991.html - 2k - 网页快照 - 类似网页

相关搜索:
java.lang


1
2
3
4
5
6
7
8
9
10
下一页

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧