Jump to content

red irect URL


padmapraveen_vasili
 Share

Recommended Posts

Hi all,i am new to java.i am developing a small application in our organization.it has a login page, and landing dashboard screen. and other business related screens.so its login + 4 jsp's.i want to know, how can i restrict a user when he tries to directly use the jsp in url.for ex: www.trainingcenter.com/all_details.jsp ?this should be allowed, when he tries to hit this...he has to be re directed to the login page.it is being developed with palin MVC architecture.let me know your solutions or suggestions.thanks in advance.praveen.

Link to comment
Share on other sites

In your MVC you should have a Base Controller that all your controllers inherit from, this makes it easy to implement code that is required on all pages.In the base controller you will need a method that checks to see if the user is logged in or not (however you deside to implement that).If the user is not logged in then you redirect to the login page. Here is a simple example in C#, sorry my Java is rusty.

class BaseController {  public BaseController() {	checkLogin();  }  private void checkLogin() {	if(HttpContext.Current.Session["LoggedUser"] == null) {	  HttpContext.Current.Response.Redirect("Login.aspx");	}  }}

If all your controllers inherit from this class then they will all automatically check for a login on initialization.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...