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)
...全文
14272 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
下一页
基于遗传算法的新的异构分布式系统任务调度算法研究(Matlab代码实现)内容概要:本文档围绕基于遗传算法的异构分布式系统任务调度算法展开研究,重点介绍了一种结合遗传算法的新颖优化方法,并通过Matlab代码实现验证其在复杂调度问题中的有效性。文中还涵盖了多种智能优化算法在生产调度、经济调度、车间调度、无人机路径规划、微电网优化等领域的应用案例,展示了从理论建模到仿真实现的完整流程。此外,文档系统梳理了智能优化、机器学习、路径规划、电力系统管理等多个科研方向的技术体系与实际应用场景,强调“借力”工具与创新思维在科研中的重要性。; 适合人群:具备一定Matlab编程基础,从事智能优化、自动化、电力系统、控制工程等相关领域研究的研究生及科研人员,尤其适合正在开展调度优化、路径规划或算法改进类课题的研究者; 使用场景及目标:①学习遗传算法及其他智能优化算法(如粒子群、蜣螂优化、NSGA等)在任务调度中的设计与实现;②掌握Matlab/Simulink在科研仿真中的综合应用;③获取多领域(如微电网、无人机、车间调度)的算法复现与创新思路; 阅读建议:建议按目录顺序系统浏览,重点关注算法原理与代码实现的对应关系,结合提供的网盘资源下载完整代码进行调试与复现,同时注重从已有案例中提炼可迁移的科研方法与创新路径。
【微电网】【创新点】基于非支配排序的蜣螂优化算法NSDBO求解微电网多目标优化调度研究(Matlab代码实现)内容概要:本文提出了一种基于非支配排序的蜣螂优化算法(NSDBO),用于求解微电网多目标优化调度问题。该方法结合非支配排序机制,提升了传统蜣螂优化算法在处理多目标问题时的收敛性和分布性,有效解决了微电网调度中经济成本、碳排放、能源利用率等多个相互冲突目标的优化难题。研究构建了包含风、光、储能等多种分布式能源的微电网模型,并通过Matlab代码实现算法仿真,验证了NSDBO在寻找帕累托最优解集方面的优越性能,相较于其他多目标优化算法表现出更强的搜索能力和稳定性。; 适合人群:具备一定电力系统或优化算法基础,从事新能源、微电网、智能优化等相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①应用于微电网能量管理系统的多目标优化调度设计;②作为新型智能优化算法的研究与改进基础,用于解决复杂的多目标工程优化问题;③帮助理解非支配排序机制在进化算法中的集成方法及其在实际系统中的仿真实现。; 阅读建议:建议读者结合Matlab代码深入理解算法实现细节,重点关注非支配排序、拥挤度计算和蜣螂行为模拟的结合方式,并可通过替换目标函数或系统参数进行扩展实验,以掌握算法的适应性与调参技巧。

81,115

社区成员

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

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