Meaningless Drivel is fun!*
The moose likes JSF and the fly likes Help - Problems with redirect in servlet filter in my JSF web app Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Help - Problems with redirect in servlet filter in my JSF web app" Watch "Help - Problems with redirect in servlet filter in my JSF web app" New topic
Author

Help - Problems with redirect in servlet filter in my JSF web app

Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 386

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.

web.xml:



ValidationFilter code:



URI value comes back as: /CSC-ARXfer/faces/index.jsp
URL value comes back as: http://machinename.cn.org:9081/CSC-ARXfer/faces/index.jsp

The error in my stack trace is as follows:




Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 386

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?

Please help. Thanks.

Here is my servlet filter:




My web.xml file looks like:




Here is the error in my stack trace:

B Nirvan
Ranch Hand

Joined: Oct 20, 2010
Posts: 82
Try removing this line


regards,
Nirvan.
Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 386

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 7.5.5.1 and with the websphere server. I don't think I've mentioned that before.

Thanks again.
B Nirvan
Ranch Hand

Joined: Oct 20, 2010
Posts: 82
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.


regards,
Nirvan.
Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 386

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:



Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 386

I actually have the second section of my servlet filter working if you can believe it but could really use some help in fixing the first section of my code.

I finally was to get the section that states if the USERID is FALSE then do the sendRedirect().

However, when the USERID is TRUE I go into a loop. Here is my code and ANY HELP/DIRECTION/SUGGESTIONS yet again would great be appreciated. Thank you.

Here is the servlet code:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help - Problems with redirect in servlet filter in my JSF web app
 
Similar Threads
Login page is not opening
WebSphere Application Server 7 could not find jndi name.
Websphere Application Server 7 ... EJB 2.0 Error :: PMGR1012E
Websphere App Server 7 and EJB 2.0 problem
JPA project classes are not found in Web module in runtime - RAD 7.5