你不能,不使用标准的API。 HttpServletRequest表示服务器接收到的请求,因此添加新参数不是有效的选项(就API而言)。

原则上,您可以实现一个HttpServletRequestWrapper的子类,它将原始请求打包,并拦截getParameter()方法,并在转发时传递包装的请求。

如果你去这个路由,你应该使用一个过滤器来替换一个HttpServletRequestWrapper的HttpServletRequest:

public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

if (servletRequest instanceof HttpServletRequest) {

HttpServletRequest request = (HttpServletRequest) servletRequest;

// Check wether the current request needs to be able to support the body to be read multiple times

if (MULTI_READ_HTTP_METHODS.contains(request.getMethod())) {

// Override current HttpServletRequest with custom implementation

filterChain.doFilter(new HttpServletRequestWrapper(request), servletResponse);

return;

}

}

filterChain.doFilter(servletRequest, servletResponse);

}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐