File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes One more Servlet Filter question, please Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "One more Servlet Filter question, please" Watch "One more Servlet Filter question, please" New topic

One more Servlet Filter question, please

Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 387

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.
Ed Ward
Ranch Hand

Joined: Jan 30, 2006
Posts: 147
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

Joined: Jun 21, 2005
Posts: 387

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.

I agree. Here's the link:
subject: One more Servlet Filter question, please
It's not a secret anymore!