Java filter and working with Servlets

Asked

Viewed 127 times

0

Good afternoon, everyone,

I’m going through a really boring problem, it should be a small detail to solve the problem and I’m lost on how to seek this information that I lack. Well, enough crying and follow the report of the problem:

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

The first request and answer is the URL itself, so the modification on top of that answer works without problems, I get the HTML answer, change with the information I want and then write inside that answer

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

The second request and replay is already another URL, a URL that performs a POST operation by responding to a JSON.

It is in this second request and answer that I am breaking my head. Since this guy’s answer is a JSON, I can’t manipulate this guy and throw a new body of html into the current URL’s html.

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

Any tips? Thanks in advance.

  • Why are you using Servlets? I imagine it is with academic purpose, because it is not ideal to treat the redirection of a system pages and the writing of your data (so its difficulty to solve the problem elegantly). For this, it is interesting to use a framework, such as JSF, for example.

  • I can’t run away from Servlet, because I’m creating a plugin on top of Jira that your entire environment was built on top of this technology. My system is just an add-on to a larger system.

1 answer

0


Well, I solved that problem differently.

Instead of creating a new html within the user response, I just direct it to my HTML page. This makes it easier to work with all kinds of requests.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.