是否可以添加到请求的可用参数(HttpServletRequest) [英] Is it possible to add to the available parameters of a request (HttpServletRequest)
问题描述
我想拦截过滤器/ servlet中的请求并向其添加一些参数。但是,请求不会公开'setParameter'方法,并且操作时参数map会抛出一个错误,说明它已被锁定。我可以尝试一种替代方案吗?
I want to intercept a request in a filter/servlet and add a few parameters to it. However, the request does not expose a 'setParameter' method and the parameter map when manipulated throws an error saying it is locked. Is there an alternative I can try?
推荐答案
子类 HttpServletRequestWrapper
并覆盖 getParameter
方法。该类的描述如下:
Subclass HttpServletRequestWrapper
and override the getParameter
methods. The description of this class reads:
提供HttpServletRequest接口的便捷实现,该接口可由希望调整请求的开发人员进行子类化。 Servlet。
Provides a convenient implementation of the HttpServletRequest interface that can be subclassed by developers wishing to adapt the request to a Servlet.
在过滤器中,将请求包装在子类的实例中。
In the filter, wrap the request in an instance of your subclass.
这篇关于是否可以添加到请求的可用参数(HttpServletRequest)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!