SSM报错处理

错误描述一

org.apache.coyote.http11.Http11Processor.service Error parsing HTTP request header
Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:476)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:687)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)

问题原因:

加载图片时, 中的路径中有特殊字符。

解决方式:

  • 去除URL中的特殊字符;
  • 使用 Post 方法提交数据
  • 更换低版本的Tomcat来规避这种问题。本文使用8.5.27版本的tomcat出现此问题;之前有类似的错误,8.5.6版本未出现过此类问题;
  • 在 Tomcat conf/catalina.properties 添加或者修改:
1
2
3
4
# 添加 
tomcat.util.http.parser.HttpParser.requestTargetAllow=|{}
# 【实测】添加了上述文件后,仍然会有400错误,在加上 encodeURIComponent方法对url进行编码之后,就可以了,希望对您有用;
# 【实测】使用8.5.6版本的Tomcat,该问题得到解决;

Tomcat在 7.0.73, 8.0.39, 8.5.7 版本后,添加了对于http头的验证。 具体来说,就是添加了些规则去限制HTTP头的规范性 org.apache.tomcat.util.http.parser.HttpParser#IS_NOT_REQUEST_TARGET[]中定义了一堆not request target if(IS_CONTROL[i] || i > 127 || i == 32 || i == 34 || i == 35 || i == 60 || i == 62 || i == 92 || i == 94 || i == 96 || i == 123 || i == 124 || i == 125) { IS_NOT_REQUEST_TARGET[i] = true; } 转换过来就是以下字符(对应10进制ASCII看): 键盘上那些控制键:(<32或者=127) 非英文字符(>127) 空格(32) 双引号(34) #(35) <(60) >(62) 反斜杠(92) ^(94) TAB上面那个键,我也不晓得嫩个读(96) {(123) }(124) |(125)

错误描述二

javax.management.InstanceNotFoundException: com.alibaba.druid:type=DruidDataSourceStat

原因:在一台服务器上启动了两个tomcat,两个tomcat都是用druid。

解决方案:

修改Tomcat 下的 catalina.sh:
修改Tomcat 下bin目录下的的 catalina.sh,:在# OS specific support. $var must be set to either true or false.与cygwin=false之间
增加此句代码: JAVA_OPTS=”-Ddruid.registerToSysProperty=true”

错误描述三

tomcat下启动多个应用时可能遇到的异常:

11-Jan-2020 17:38:17.244 信息 [mysql-cj-abandoned-connection-cleanup] org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading Illegal access: this web application instance has been stopped already. Could not load []. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load []. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1311)
at org.apache.catalina.loader.WebappClassLoaderBase.getResource(WebappClassLoaderBase.java:986)
at com.mysql.cj.jdbc.AbandonedConnectionCleanupThread.checkThreadContextClassLoader(AbandonedConnectionCleanupThread.java:117)
at com.mysql.cj.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:84)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

原因:从日志文件可以看出是说Web应用程序根系统属性已经被设置,’webapp.root’ 这个配置名称已经被使用,提示了Choose unique values for the ‘webAppRootKey’ context-param in your web.xml files ,也就是说在web.xml里配置一个唯一的’webAppRootKey’ ,这样就不会发生冲突。

解决办法
在web.xml指定webAppRootKey

1
2
3
4
<context-param>  
<param-name>webAppRootKey</param-name>
<param-value>myapp.root</param-value>
</context-param>