关于java.lang.IllegalStateException
今天调试程序时遇到了java.lang.IllegalStateException org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:423)这个异常,百度了一下引起这个异常的原因是如下:
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 interdivts it as relative to the current request URI. If the location is relative with a leading '/' the container interdivts 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
经分析我这边的情况是第一种即在同一个方法中一次以上的连续调用了response.sendRedirect()方法,知道根源解决方法就比较简单了,避免多次连续的调用response.sendRedirect()方法。
这个问题在我们的系统中,是因为判断是否有注入式攻击字符时产生的,因为CR、LF在不同的系统中表示不同的回车换行的意义,在判断是否为注入攻击的字符时他俩也在其列,不过从前台返回的字符中难免不包含这两个字符的,当然,我们现在关心是产生上面的异常的原因,就是上面的1)2)两个原因,而根源和判断是否有注入攻击字符相关
扩展链接:
1:深入理解ServletRequest与ServletResponse
http://lavasoft.blog.51cto.com/62575/275586
2:HttpServletRequest、 ServletRequest、Request
http://blog.163.com/magicc_love/blog/static/185853662201201023521297/
3:关于linux和windows的CR, LF, CR/LF 回车 换行问题
http://www.cnblogs.com/lihong/archive/2011/02/19/1958349.html
http://www.360doc.com/content/11/0113/20/3508740_86319358.shtml
当然,这个问题的解决过程是一个很好的锻炼过程,同时也证明对于问题本身的求解必须具备打破沙锅问到底、不达目的不罢休的态度,才能够对问题本身有比较深入的了解,也才能找到问题的根源,从而从根本上将问题彻底解决!
关于java.lang.IllegalStateException的更多相关文章
- myeclipse 无法启动 java.lang.IllegalStateException: Unable to acquire application service. Ensure that the org.eclipse.core.runtime bundle is resolved and started (see config.ini).
把myeclipse10 按照目录完整拷贝到了另外一台电脑, 另外的目录 原安装目录 D\:\soft\i\myeclipse10 新安装目录 E\:\soft\myeclipse10 双击启动失败, ...
- java.lang.IllegalStateException:Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx...}: java.lang.IllegalSta ...
- java.lang.IllegalStateException: Not allowed to create transaction on shared EntityManager - use Spring transactions or EJB CMT instead
java.lang.IllegalStateException: Not allowed to create transaction on sharedEntityManager - use Spri ...
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exceptionjava.lang ...
- 用java实现文件下载,提示java.lang.IllegalStateException: getOutputStream() has already been called for this response
1. 用java实现文件下载,提示java.lang.IllegalStateException: getOutputStream() has already been called for this ...
- eclipse启动报错java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' befo
报错: java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invo ...
- java.lang.IllegalStateException: Couldn't read row 1, col 0 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data fr
Android中操作Sqlite遇到的错误:java.lang.IllegalStateException: Couldn't read row 1, col 0 from CursorWindow. ...
- java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
在ViewPager中,用Fragment显示页面时,报错: java.lang.IllegalStateException: The specified child already has a pa ...
- java.lang.IllegalStateException:Web app root system property already set to different value 错误原因及解决 Log4j
Log4j是Apache的一个开放源代码项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台.文件.GUI组件.甚至是套接口 服务器.NT的事件记录器.UNIX Syslog守护进程等: ...
- 关于viewpager 里嵌套 listview 同时实现翻页功能的“java.lang.IllegalStateException: The specified child..."异常处理
这几天做项目用到了ViewPager,因为它可以实现左右划动多个页面的效果,然后 再每个页面里使用ListView,运行时总是出现”PagerAdapter java.lang.IllegalStat ...
随机推荐
- Win7系统安装Centos7.0双系统(二)
4.6语言选择
- mousewheel滚轮事件 浏览器的写法
鼠标的滚轮事件,在Jquery中有对应的一个插件:https://github.com/brandonaaron/jquery-mousewheel 原生的滚轮事件:火狐与其他浏览器使用了不同的事件 ...
- JavaScript权威指南 第二章 词法结构
这章主要把保留字说一下 JavaScript 把一些标识符拿出来用做自己的关键字.因此,就不能再在程序中把这些关键字用做标识符了: break delete function return typeo ...
- DBA_Oracle Event等待事件分析(概念)
2014-12-18 Created By BaoXinjian
- BestCoder HDU 5750 Dertouzos
Dertouzos 题意: 有中文,不说. 题解: 我看了别人的题解,还有个地方没懂, 为什么是 if(d%prime[i]==0) break; ? 代码: #include <bits/st ...
- phpmyadmin数据库导入出错
SQL 查询: -- phpMyAdmin SQL Dump-- version 3.5.1-- http://www.phpmyadmin.net---- 主机: localhost-- 生成日期: ...
- 使用UltraEdit+BCC5.5搭建C语言学习环境(转)
今天闲来无聊,想起以前学的C都差不多忘光了,想练练,先搭环境吧,vc bc之类都太大了,我以前在borland下过一个命令行编译工具不错,好像以前看到有人用ultraedit配合命令行工具做过一个开发 ...
- ylbtech-LanguageSamples-XMLdoc
ylbtech-Microsoft-CSharpSamples:ylbtech-LanguageSamples-XMLdoc 1.A,示例(Sample) 返回顶部 “XML 文档”示例 本示例演示如 ...
- 一款监控网络状态的好工具- Smokeping
最近工作中需要监测某个分公司到IDC机房的网络情况,到网络上找了不少软件,发现一款叫smokeping的开源软件还不错,它是rrdtool的作者制作的,在图形显示方面很漂亮,可以用来很好的检测网络状态 ...
- git同步开发更新至项目目录(转载)
From:http://toroid.org/ams/git-website-howto 本地版本库中存放开发的项目代码.以下内容介绍如何将本地版本库修改通过执行“git push web”命令同步到 ...