关于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 ...
随机推荐
- python学习-day02
---恢复内容开始--- 一.pycharm安装 1.1破解方式http://www.cnblogs.com/evlon/p/4934705.html 1.2.头部配置: 二.运算符 2.1.比较运算 ...
- SVN 分支及合并的介绍和实践---命令行
写在前面 一些相关的概念和原理 进行分支开发的最佳实践 合并的分类 在 Eclipse 中进行合并操作 相关资源 写在前面 本文是由演讲整理而来的,介绍了 SVN 分支与合并的概念.流程和一些实际操作 ...
- SQL Server 2012 批量重建索引
关于索引的概念可以看看宋大牛的博客 T-SQL查询高级—SQL Server索引中的碎片和填充因子 整个数据库的索引很多,索引碎片多了,不可能一个个的去重建,都是重复性的工作,所以索性写了个存储过程, ...
- Redis简单使用方法说明
安装 www.redis.io下载安装包tar zxvf redis.tar.gzcd redismakecd src && make install移动文件,便于管理:mkdir - ...
- Standing on Shouder of Giants
Zachary_Fan 如何一步一步用DDD设计一个电商网站(二)-- 项目架构 http://www.cnblogs.com/Zachary-Fan/p/6012454.html HTTP 权威指南 ...
- c语言知识(1)
用freopen重定向输入 freopen函数以指定模式重新指定到另一个文件,模式用于指定新文件的访问方式. FILE *freopen(const char * restrict filename, ...
- Linux重置mysql密码(转载)
From:http://hi.baidu.com/mcspring/item/6358ee27afe7e1c8a5275ab7 首先,必须拥有MySQL操作的所有权限: 其次,停止MySQL服务: / ...
- linux命令行下导出导入.sql文件
一.导出数据库用mysqldump命令(注意mysql的安装路径,即此命令的路径):1.导出数据和表结构(以管理员身份运行): ------------------------------------ ...
- 如何为PHP贡献代码
PHP在之前把源代码迁移到了git下管理, 同时也在github(https://github.com/php/php-src)上做了镜像, 这样一来, 就方便了更多的开发者为PHP来贡献代码. 今天 ...
- vmware虚拟机挂起后无法再恢复(转)
之前一直使用vmware调试程序,但有一天它被挂起后,就一直无法恢复. 提示: 无法获取该配置文件上的排他锁 另一个VMware进程可能正在使用此配置文件. 后来在google里查了一下,发现其实是一 ...