Home 在请求目标中找到无效字符。有效字符在RFC 7230和RFC 3986中定义
Post
Cancel

在请求目标中找到无效字符。有效字符在RFC 7230和RFC 3986中定义

报错信息

1
2
3
4
5
6
7
8
9
10
11
java.lang.IllegalArgumentException: 在请求目标中找到无效字符有效字符在RFC 7230和RFC 3986中定义
  org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:504)
  org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:503)
  org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
  org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:818)
  org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1626)
  org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
  java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  java.lang.Thread.run(Thread.java:748)~

报错原因

这个错误的原因是JSP传递参数时传递了中文,而项目使用的是高版本的Tomcat,高版本的Tomcat传递参数不兼容。

解决方法

对传入的中文参数进行encodeURI()处理。

1
2
3
4
5
6
7
8
function chenge() {
    var frm = document.userFrom;
    var userId = frm.userId.value;
    var userName = frm.userName.value;  
    userName = encodeURI(userName);
    var url = "userAction.do?action=User&userId=" + userId + "&userName=" + userName;
    window.location.href = url;
}
This post is licensed under CC BY 4.0 by the author.