[request by Put] failed to parse the parameters and put it back to Request by HttpServletRequest

questions about parsing parameters in request and putting them back in request

get and post follow the method , parsing is normal, but an exception is thrown when a put request is encountered.

put requests request of spring , while tomcat is request of apache . Although they all inherit from HttpServletRequest , they throw a class conversion exception

when converting request .

has tried many methods, but all of them are ineffective in the end. the requirement to be realized is that the client passes the parameters, the interceptor parses the parameters and re-assigns them, and the control layer acquires the re-assigned parameters and does the corresponding logic.

this is the initialization assignment

private static Field requestField;  
  
private static Field parametersParsedField;  
  
private static Field coyoteRequestField;  
  
private static Field parametersField;  
  
private static Field hashTabArrField;  

.....

try {  
    Class clazz = Class.forName("org.apache.catalina.connector.RequestFacade");  
    requestField = clazz.getDeclaredField("request");  
    requestField.setAccessible(true);  
  
    parametersParsedField = requestField.getType().getDeclaredField("parametersParsed");  
    parametersParsedField.setAccessible(true);  
  
    coyoteRequestField = requestField.getType().getDeclaredField("coyoteRequest");  
    coyoteRequestField.setAccessible(true);  

    parametersField = coyoteRequestField.getType().getDeclaredField("parameters");  
    parametersField.setAccessible(true);  
  
    hashTabArrField = parametersField.getType().getDeclaredField("paramHashStringArray");  
    hashTabArrField.setAccessible(true);  
} catch (Exception e) {  
    e.printStackTrace();  
}  

resolve request parameters in this method

    Object innerRequest = requestField.get(request);//
    parametersParsedField.setBoolean(innerRequest, true);
    Object coyoteRequestObject = coyoteRequestField.get(innerRequest);
    Object parameterObject = parametersField.get(coyoteRequestObject);
Mar.01,2021

this method is not recommended, and it has been explained in the article corresponding to the connection that you can use the form of the wrapper class. It is safe and efficient to handle in the form of wrapper classes

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e79695-4dc23.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e79695-4dc23.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?