Filter in Java and working with Servlets

0

Good afternoon guys,

I'm going through a really annoying problem, it must be a little detail to solve the problem and I'm lost in how to get this information that I lack. Well, enough of crying and following the problem report:

I'm creating a java filter with Servlets to capture all requests that happen in the / * context, meaning that my filter will be called on all my system URLs, and depending on the URL the filter checked, I go I want to change the HTML of the current page of the user (I say current and not the URL in question because the filter goes through all the requests, but I want to change only the HTML of the first request, which is the URL that the user is accessing).

The first request and response is the URL itself, so the modification on top of that answer works without problems, I pick up the answer in HTML, change it with the information I want, and then write within that response.

httpResponse.getOutputStream().write(generateHTML().getBytes())

The second request and response is already another URL, a URL that performs a POST operation giving a JSON response.

It's in this second request and response that I'm breaking my head. Since this guy's response is a JSON, I can not manipulate this guy and throw the user a new body of html within the html of the current URL.

I thought of something like saving the response of the first filter made, so when the URL that I try to pass through the filter, I can change the response only of the filter that was already done at the beginning, but to no avail ...: /

Any tips? Thank you in advance.

    
asked by anonymous 18.05.2018 / 22:32

1 answer

0

Well, I solved this problem differently.

Instead create a new html within the user's response, I just direct it to my page that contains the HTML. This makes it easier to work with all types of requests.

    
10.08.2018 / 21:18