Tomcat exception solution (Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986)

Tomcat exception solution (Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986)

1. Scenario display

The tomcat log occasionally reports the following exception information. What is going on?

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.AbstractNioInputBuffer.parseRequestLine(AbstractNioInputBuffer.java:283)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1017)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

The page cannot be opened

2. Cause Analysis

This means that the request header contains illegal characters defined in the RFC 7230 and RFC 3986 specifications, which will cause the page to report a 400 exception.

The reason is: the version of tomcat is too high. It is said on the Internet that tomcat versions higher than 7.0.73 add verification of http headers (request headers).

Get request, that is, question mark passing parameter, means there is only request header, no request body

The RFC3986 document stipulates that a URL is only allowed to contain English letters (a-zA-Z), numbers (0-9), -_.~4 special characters, and all reserved characters.

RFC3986 specifies the following characters as reserved characters: ! * ' ( ) ; : @ & = + $ , / ? # [ ]

At the same time, the RFC 3986 specification was already proposed in the tomcat 7.0.73 version, and RFC 7230 is also a supplement or improvement to the former, so this problem will occur in tomcat 7.0.73 and above.

Note: This situation only occurs in IE browser, because IE browser does not encode Chinese parameters, while other types of browsers will automatically encode Chinese by default.

3. Solution

Method 1: Lower the tomcat version;

After testing, it was found that the description of the maximum version requirement of Tomcat on the Internet was incorrect. It is not necessary to have a version lower than 7.0.73.

I downloaded a tomcat7.0.70. After running the project, there was still a character set error, which caused the web page to be unable to open.

However, I tested tomcat7.0.61 and found that the project ran perfectly normally. The console no longer reported errors and the web pages could be opened normally.

64-bit download address: https://archive.apache.org/dist/tomcat/tomcat-7/v7.0.61/bin/apache-tomcat-7.0.61-windows-x64.zip

32-bit download address: https://archive.apache.org/dist/tomcat/tomcat-7/v7.0.61/bin/apache-tomcat-7.0.61-windows-x86.zip

Method 2: Change the get request to a post request; (recommended)

Method 3: get request (question mark parameter passing)

Use the URIEncoder() function to encode Chinese characters

The above is the detailed content of the tomcat exception solution (Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986). For more information about tomcat exception solution, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Tomcat common exceptions and solution code examples
  • SpringBoot project is packaged and published to external tomcat (solving various exceptions)
  • A solution to the abnormal exit of Tomcat caused by semaphore
  • Analysis and solution of abnormal problem of loading jar in tomcat
  • Causes and solutions for the exception getOutputStream() has already been called for this response in jsp under tomcat6
  • Error when starting tomcat: The proxy threw an exception: java.rmi.server.ExportException: Port already in use: 1099 Solution
  • Solve the problem that idea2020.2 encounters an error in the pom.xml file Maven plugin tomcat7
  • Solve the problem of IDEA configuring tomcat startup error
  • Solve the problem of error 404 when starting tomcat after importing ssm project into idea
  • Tomcat startup error: solution to java.util.zip.ZipException

<<:  Notes on the MySQL database backup process

>>:  How to get USB scanner data using js

Recommend

17 JavaScript One-Liners

Table of contents 1. DOM & BOM related 1. Che...

JavaScript Basics: Scope

Table of contents Scope Global Scope Function Sco...

How to start a Vue.js project

Table of contents 1. Node.js and Vue 2. Run the f...

jQuery implements the mouse drag image function

This example uses jQuery to implement a mouse dra...

HTML Tutorial: Collection of commonly used HTML tags (4)

Related articles: Beginners learn some HTML tags ...

Linux tutorial on replacing strings using sed command

To replace a string, we need to use the following...

Use of vuex namespace

Table of contents Since Vuex uses a single state ...

Vue3 Vue Event Handling Guide

Table of contents 1. Basic event handling 2. Send...

A brief talk about cloning JavaScript

Table of contents 1. Shallow cloning 2. Deep clon...

Detailed explanation of uniapp's global variable implementation

Preface This article summarizes some implementati...

Detailed tutorial on how to install mysql8.0 using Linux yum command

1. Do a good job of cleaning before installation ...

A brief introduction to MySQL functions

Table of contents 1. Mathematical functions 2. St...