Servlet includes runs HTTP headers in Tomcat

I have a servlet that includes the request manager of another servlet.

The incoming servlet sets the headers that I would like to read in the included servlet. Therefore, I pass the custom HTTPResponse object in the include () method, which captures all feedback activity from the servlet.

The problem is that the headers are not customizable in my custom answer. I ran debug and looked at what looks like Tomcat, which terminates my custom response object with its own response object. When calling setHeader, this class is carried over and never extends to my custom response object.

I think Tomcat does this to protect the client from headers set in the wrong place. The funny thing is that the same approach works as I expected in Jetty.

It has been a long time since I took up the servlet seriously, so I'm struggling a bit. I am trying to understand how to read response headers from a servlet that are called through dispatcher.include ().

+3
source share
1 answer

In the specification section of the servlet SRV.8.3:

The method for enabling the RequestDispatcher interface can be called at any time. The target servlet of the include method has access to all aspects of the request object, but its use of the response object is more limited.

ServletOutputStream Writer , flushBuffer ServletResponse.

- , . .

request.setAttribute(...), , ? ?

+4

Source: https://habr.com/ru/post/1767595/


All Articles