今天调试程序时遇到了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的更多相关文章

  1. 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 双击启动失败, ...

  2. 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 ...

  3. 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 ...

  4. java.lang.IllegalStateException: getOutputStream() has already been called for this response

    ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exceptionjava.lang ...

  5. 用java实现文件下载,提示java.lang.IllegalStateException: getOutputStream() has already been called for this response

    1. 用java实现文件下载,提示java.lang.IllegalStateException: getOutputStream() has already been called for this ...

  6. eclipse启动报错java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' befo

    报错: java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invo ...

  7. 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. ...

  8. 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 ...

  9. java.lang.IllegalStateException:Web app root system property already set to different value 错误原因及解决 Log4j

    Log4j是Apache的一个开放源代码项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台.文件.GUI组件.甚至是套接口 服务器.NT的事件记录器.UNIX Syslog守护进程等: ...

  10. 关于viewpager 里嵌套 listview 同时实现翻页功能的“java.lang.IllegalStateException: The specified child..."异常处理

    这几天做项目用到了ViewPager,因为它可以实现左右划动多个页面的效果,然后 再每个页面里使用ListView,运行时总是出现”PagerAdapter java.lang.IllegalStat ...

随机推荐

  1. sublime安装DocBlockr注释插件

    点击sublime的菜单栏 view->show console :现在打开了控制台, 这个控制台有上下两栏, 上面一栏会实时显示sublime执行了什么插件,输出执行结果, 如果你安装的某个插 ...

  2. "aa".equals(name)这种写法为什么就可以避免空指针

    public static void main(String[] args) { String name=null; if("aa".equals(name))//这种情形,不出现 ...

  3. linux下mongodb定时备份指定的集合

    目标:把一台linux机上mongodb的数据定时备份到另一台机上: 过程: 一开始打算使用mongoexport和mongoimport,但是总是会报“\x00”字符串不能识别的问题,后来就改成了m ...

  4. (WPF, MVVM) Slider Binding.

    对于Button的Command的绑定可以通过实现ICommand接口来进行,但是Slider并没有Command属性. 另外如果要实现MVVM模式的话,需要将一些Method和Slider的Even ...

  5. PLSQL_性能优化工具系列02_SQL Tuning Health-Check Script (SQLHC)

    2014-08-23 Created By BaoXinjian

  6. DBA_Oracle Startup / Shutdown启动和关闭过程详解(概念)

    2014-08-07 Created By BaoXinjian

  7. 502 bad gateway 可能的错误原因

    1.PHP程序的执行时间超过了Nginx的等待时间,可以适当增加nginx.conf配置文件中FastCGI的timeout时间 #http代码段中增加 fastcgi_connect_timeout ...

  8. java NIO经典实例

    服务端: Loader.java package net.chatroom.server; public class Loader { public static void main(String[] ...

  9. json字符串转json对象的方法

    在使用$.ajax()方法时,我们可以设置dataType:'json'的参数,便可以拿到后台返回的json数据对应的json对象.但有时,我们拿到的是json字符串,需要将它再转成json对象来使用 ...

  10. SQL查詢數據字典

    SELECT d.name AS 表名 , f.value AS 表说明, 字段序号 = a.colorder , 字段名 = a.name , 标识 THEN '√' ELSE '' END , 主 ...