請求參數包含 % 字符時,Tomcat/Spring MVC 直接報 400 Bad Request,日誌顯示 Invalid character found in the request target。
% 在 URL 中為編碼前綴(如 %20 代表空格)。單獨出現 % 且後跟非十六進制字符,違反 RFC 3986,容器拒絕解析。
encodeURIComponent(param) 發送請求。URLDecoder.decode,無需手動處理。server.xml 添加 relaxedQueryChars="%",但會降低安全性。// 前端
fetch('/api?param=' + encodeURIComponent('100%'))
@Controller
@GetMapping("/api")
public String api(@RequestParam String param) {
// param 自動解碼為 "100%"
}