I have an HTML page which is controlled by jquery i.e. I have implemented jquery specific syntax to read "click" of a button.So there is no Java controller (i.e. Spring controller or a servlet) involved here.For data fetching and updating I am using DWR(direct web remoting) framework calls.
Now there is a requirement to force users to redirect to a Login screen - that will just have username,password and submit button.So anytime user accesses the HTML page without authentication(meaning cookies are not there in browser),he should be forced to enter username and password.
In effect,when user accesses http://hostname/context/management.html without authenticating himself,he should be directed to http://hostname/context/login.do .After entering correct authentication details and pressing submit button,he should again be taken to http://hostname/context/management.html .
What is the best way to do it ?is it even possible with the current design that I have in place?
So I can configure a filter for my url pattern.
Now my next question is how I can use a filter to show a JSP or an HTML page(in this case login page)?
I know these questions are very basic but I have never done this before.
Appreciate your patience.
Paul Clapham wrote:Usually this sort of thing is handled by a servlet filter.
You have observed that I didn't post a lot of detail explaining what a servlet filter was or how to write one. That's because if you google for "servlet filter tutorial" you will find... some servlet filter tutorials. There is no point in me writing a servlet filter tutorial for you personally, because somebody else has already done that and put them on the Internet where everybody can find them. And they have done a better job than I would have.
So don't just sit there waiting. There's a ton of information on the web free for you to find.
Joined: Jun 19, 2004
I have been looking at filter tutorial since yesterday - but all examples end with this line of code -
I need filters to show an HTML or JSP page(login screen).
In my code there is no controller so I cannot set an attribute in request in filter code and read it afterwards .
I don't understand. The filter will run because a request for a particular servlet or URL was received. Calling the chain.doFilter response simply causes that request to be processed in the normal way.
So yeah, it's true that setting a request attribute would be pointless if the request was an HTML page, since it couldn't do anything with that attribute. But don't any of the examples in your tutorial involve forwarding or redirecting to some other page? That would be the normal way to make your users go to the login page instead of whatever they asked to go to.
Joined: Jun 19, 2004
Paul Clapham wrote:
But don't any of the examples in your tutorial involve forwarding or redirecting to some other page? That would be the normal way to make your users go to the login page instead of whatever they asked to go to.
Ok thanks Paul - I think this was the hint I needed.