Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

One more Servlet Filter question, please

 
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
How can I configure my web app whereby my validation servlet filter will only execute when the URL is executed initially?

I do not want the servlet filter executed each time I reload the web page when a transaction has been completed in order to get the user ready to enter another transaction. The issue is the USER parameter in the original request is NOW NULL because it is missing from the URL when the web page is reloaded. I'm not sure why that is because it used to be on the URL when the page was reloaded but I'm not even getting to the method in my bean that actually processes the transaction because the doFilter() in my servlet is executing before that is done.

Below please find the web.xml file and the config of the servlet:



Here is the servlet code as well:



Any help/direction would be greatly appreciated. Thank you.
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems like you are trying to control the flow from your filter logic.

Reading through your conditional expressions I'm a little confused as to what you are trying to accomplish. I mean, if /index.jsp is not at index 17 of the uri, you call doFilter. If it is, then an attempt to get the userId parm is made, if it is null, then you do a sendRedirect to a validation failed jsp. If userId is not null then a validation attempt is made and another if block executes. This one says if validateUser is true or the URI endsWith "/CSC-ARXfer/faces/validationFailed.jsp". I don't know that at this point in the code the URI is ever going to end with that string, so it seems unnecessary. If the result of this condition is false then a sendRedirect is executed.

Confused? I am a little too.

The way the code is, userService.validateUserID(userID); is only going to execute if the userId parm is not null and indexUri == 17.
Print out the URI string before evaluating it to see if it is what you expect.
Are you submitting the userId parm as part of your form everywhere it needs to be?

Lastly, you may want to consider revisting your page URL scheme for the app and catch only those requests that you want "filtered" via the filter <url-pattern> in web.xml. It may mean changing the URI of some pages, but I think this would simplify things a bit.
Short of that, maybe taking out the if (indexURI == 17) evaluation will give you want you want, since you are checking for userId != null anyway before calling the userService bean.
 
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
Ed - you're correct that I was completely confused. I was finally able to resolve my issue. Basically I started over and was able to get my servlet filter to work properly.

I thank you for your time in responding and your input.

Regards.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic