Im trying to use a single filter for my servlets and jsp's. The filter works perfectly fine with the jsp's(placed in the pages subfolder ). However , when I try to apply the same filter to a set of servlets by modifying their url patterns I face a difficulty .
I modify the mapping in the web .xml as below
and a corresponding change in the associated jsp by making it submit to the following path
When I submit to the servlet from the corresponding jsp , I get 404 error , any idea what I could be doing wrong?
Thank you for your time.
Well , the fact is that the' Action ' was working perfectly up until the addition of 'secure/' to enable the mapping of URL's .Also how do I print the action URL in the servlet?
Joined: May 14, 2004
I was asking you to print the URL in JSP using JSTL.
Anyway did you try using "<servlet-name>" instead of "<url-pattern>". I know that this would be workaround but that will help you to check if request reaches to the servlet via filter.
Bear Bibeault wrote:Does it work when you disable the filter?
Nope. Doesnt work even when I disable filter as in remove the filter mapping to secure and leave the jsp and url pattern mapping in the web.xml untouched
@ Amit, I didnt quite understand what you meant there.
Sorry for following this up so late , had to be involved with another project. I've tried to fix this issue without success. The thing is the whole web app is running perfectly and everything is taken care except this security feature.
I've also tried logging and this is the log that I'm able to generate when I access the system through the servlet. And with reference to Bear's earlier question , I only meant to say that the system does not work when I change the url mappings .
This is the code in my filter:
And the logs, seem perfectly normal too:
Coming from http://localhost:8080/CISSource/ The previous page null
Checking does not belong to be checked
The previous page null
I lost track of what you think your problem is. If it's that "previous page" business... you shouldn't be surprised that it always shows up as null, because you don't have any code which assigns a value to it. And it must be an instance variable of the filter, which seems like a really bad idea to me, because it certainly isn't a local variable in the method you posted.
I also can't see where you have anything which logs "Coming from". Perhaps the code you showed us isn't the code which is running?
Thanks for the reply Paul
Yes I understand that , the problem is that I'm not being able to secure the servlets . in a manner that Im trying to secure my web pages . I have already explained what Im trying to do to secure it , in the first post of this thread .
And No I did not mean to show the 'previous page ' as the source of the problem , I only meant to show whatever logs that are generated when the filter is called.And In context ,it doesnt even make sense . Would you mind telling me what logs are you wanting to see?
As already pointed out, if the servlet doesn't work without the filter, adding one will not make it magically start to work. Have you gotten the servlet to work without the filter? If not, we're all wasting our time.
In short ,Yes the servlet does work without the filter . The only instance during which it fails is when I modify the url mapping , and here too its not failing or anything . Its just throwing a 404 when I redirect to it from the JSP .Hope Im being clear in getting my point across.
Thanks for the reply !
If by redirect url you mean the
<url-pattern > in web.xml , and the corresponding path to which the jsp submits to be modified , this is what Im doing(Like I tried in the first post)
And in the web page .
This throws the 404 error.
Or are you meaning something completely different by redirect-url?
You didn't answer my question, but I can see that the redirect URL does not start with the context path. Page-relative URLs such as that which you are using are almost guaranteed to cause trouble. Start all client-URLs (which includes redirect URLs) with the context path.
Bear Bibeault wrote:You didn't answer my question, but I can see that the redirect URL does not start with the context path. Page-relative URLs such as that which you are using are almost guaranteed to cause trouble. Start all client-URLs (which includes redirect URLs) with the context path.
Okay two things .
Firstly your questions were.?
Bear Bibeault wrote:What is the URL you are using to redirect? Does it contain the context path?
I think I answered this in my post above and you clarified that it does not contain the context path .
How do I add the context path?
I was under the assumption that request.getContextPath(), got me the context path , if not what do I need to do to get it?
Bear Bibeault wrote:You forgot the slash after the context path.
Note that for the root application, the context path is the empty string.
Okay fine. Im doing that now and getting to print the url as well . in this snippet
The URL prints as --URL/CISSource/pages/search.jsp but the 404 still remains , to clarify the structure of my project , CISSource is the name of my project and all my pages including the search page are stored inside the pages folder , what else am I missing from the url?
Thanks for your reply Vijitha!
The problem stands solved , like Bear pointed out it, I had to just insert a blank space to indicate the empty string . in place of the context path .
As for your question Im mapping all my jsp's to the /pages/* as they are placed in the pages folder.
Once again Thanks a ton Bear and Paul!
subject: 404 Error when trying to use a filter for a servlet