In an attempt to validate a valueID BEFORE a specific web page is rendered I am trying to create a servlet filter for validation purposes. The issue that I am running into is that the page cannot be forwarded within my application. I am running this web app locally and so I'm sure my configuration somewhere is wrong.
Any help/direction would be greatly appreciated. Thank you.
After much googling and other list server input I have not been able to find a solution using a SERVLET FILTER to authenticate the user BEFORE the page has started to render.
My understanding was that a servlet filter was the way to go to response.sendRedirect() before the response was committed. But per the error I'm getting it looks like the response is already committed.
I have no idea what I'm doing wrong and any HELP/DIRECTION again, would be appreciated. This can't be this difficult... can it?
Nirvan, thanks for the reply. I tried your suggestion to remove the line of code you indicated above, however, when I did , my code went into a loop and then the request parameter that I was pulling for "user" was then NULL and consequently I got an NPE.
Here is the error stack trace:
Any other suggestions or direction would be appreciated. Just an FYI, I am working in RAD 22.214.171.124 and with the websphere server. I don't think I've mentioned that before.
Joined: Oct 20, 2010
The url pattern specified by you in web.xml is (<url-pattern>*.jsp</url-pattern>), which means all the requests are intercepted by your filter and this also includes request to index.jsp. So suppose you have a valid userId entered by user, then the browser will be redirected to your index.jsp. When the request to index.jsp reaches your server, the filter again springs up and the whole process goes on again. So in short there should be some logic in your filter that will only intercept the original request and not index.jsp (or any other resource for that matter).
I am using a filter for the similar case as yours to authenticate users. Here is some code from that filter that will make my point clear.
In my code below, if the validatedUser == true then I get stuck in a loop in that the method completes but then I come right back into the method yet again and again and... The page is never redirected to the index.jsp page. If the user is NOT validated the sendRedirect to the validationFailed.jsp page works great but if the user IS validated then again I'm just stuck in that the doFilter() is just executed repetitively.
The only thing that I can think of is that the REDIRECT for a validated user is the SAME as the URI. Is that issue? If so, how can I correct this?
I do not understand what am I doing wrong? If the user IS validated how can I just redirect this user to the "/CSC-ARXfer/faces/index.jsp" page? That is all I'm needing to do.
Any help/direction/suggestion would be greatly appreciated. Here is the code: