Change ContentType or CharacterEncoding in Java Filter ONLY IF ContentType === JSON

前端 未结 6 1177
鱼传尺愫
鱼传尺愫 2021-01-01 04:32

I\'m trying to ensure that all JSON responses from a Jersey based java application have a UTF-8 character encoding parameter appended to their ContentType header.

So

6条回答
  •  时光取名叫无心
    2021-01-01 05:30

    Not 100% sure I got what you're trying to achieve. Do you want to set the header charset after calling

    chain.doFilter(request, response)
    

    ?

    If that is the case I'm afraid you cannot because very likely at that point, after that chain.doFilter(request, response) has returned and the request processed, the content charset has already been sent to the client and therefore you cannot alter it anymore.

提交回复
热议问题