resetting a HttpRequest after calling request.getReader()

后端 未结 2 1028
心在旅途
心在旅途 2020-12-31 08:21

Is there a way to call the getReader() method on a HttpRequest and then \"reset\" the request so other calls to getReader() will not t

2条回答
  •  有刺的猬
    2020-12-31 08:49

    The simple answer is "No".

    The stream is not resettable and there's no API method that will allow you to reopen it. (And for good reason. It would require the servlet infrastructure to keep a copy of the input just in case the servlet decided to reopen the stream. That would be an unwarranted overhead.)

    If you want to do this kind of thing, you will need to write your code to keep its own copy of the data. If you are implementing this in a Filter (or a Tomcat Valve) then you could create a HttpServletRequestWrapper to hide the fact that you've already read the data .... as suggested by @Vineet.

提交回复
热议问题