File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes redirect all jsp to login page only Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "redirect all jsp to login page only" Watch "redirect all jsp to login page only" New topic

redirect all jsp to login page only

Sharad Raj

Joined: Apr 27, 2012
Posts: 2
I have created a Web Application using struts 1.0, written almost 8 jsp. The problem is after starting application, when I change URL and provide /somejsp.jsp, instead of my start jsp it will lead to somejsp.jsp file, which is not required. I do not want to keep my jsp inside WEB-INF. Is there any way to modify application so that whenever user changes URL, it will lead to login page only, instead of /somejsp.jsp
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

Put a filter or interceptor on.

If the user is not logged in, redirect them to the login.

If they are logged in, and somejsp.jsp does not exist you could built a customer error page.

Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

I assume that when you say "user changes URL", you mean that the user is going to the browser's address bar and modifying the URL visible there, right?

Well, the server has no way of knowing how the URL of a request was generated. Whether it was generated by the user clicking on a link or by the user typing in the address bar, the server can't tell.
Mohana Rao Sv
Ranch Hand

Joined: Aug 01, 2007
Posts: 485

I do not want to keep my jsp inside WEB-INF.

We can be access them directly. Refer the following thread JSP's should Inside WEB-INF

ocjp 6 — Feeding a person with food is a great thing in this world. Feeding the same person by transferring the knowledge is far more better thing. The reason is the amount of satisfaction which we get through food is of only one minute or two. But the satisfaction which we can get through the knowledge is of life long.
Sharad Raj

Joined: Apr 27, 2012
Posts: 2
Hi William,

Yes, we can use interceptors or filters. Could you send me code please? Do I need to put code in web.xml and create a separate class?

Sp Wong

Joined: Jan 29, 2012
Posts: 4
Not sure if this is what you want?

Add this at the Struts-config.xml:

And your class file, it should be something below:

I agree. Here's the link:
subject: redirect all jsp to login page only
jQuery in Action, 3rd edition