Jump to content

red irect URL


padmapraveen_vasili

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...