• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try removing this line


regards,
Nirvan.
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic