22.1. Authorization Filter Example

Sunday, January 23, 2011 Posted by Sudarsan
Welcome Back !!!

Here I am going to describe the most important topic related to Java Web, i.e Security.

To authorize a person in a web and serving resources to authorized persons over the web we can use Java Filter technology !!

So have a look at the fallowing Example !!!

Create the directory Structure as shown below !!!

Directory Structure


Then create and write the fallowing Java Resources to run this Application as shown below in the images !!


index.jsp


view.jsp



error.jsp



User.java



FilterDispatcher.java


LoginServlet.java


LogOutServlet


After creating the above pages, run your project and observe how Filter is going to intercept the requests and responses.

Type view.jsp in the browser address bar without Login credientials, the browser will redirect to error.jsp page, since the user does not provided the UserName and Password.

If the user provides the Login Details the browser will redirect to view.jsp page !!
Labels:

Post a Comment