This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes Resource Restriction using web.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Resource Restriction using web.xml" Watch "Resource Restriction using web.xml" New topic
Author

Resource Restriction using web.xml

PrachiS Shah
Greenhorn

Joined: Sep 02, 2010
Posts: 10
I am having a concern regarding the Form Based authentication in Java. I need to restrict the access of jsp pages to the user, until and unless he logs in. This is the code for that;

<web-resource-collection>
<url-pattern>*.jsp</url-pattern>
</web-resource-collection>

I have jsp pages in a folder called jsp, images in a folder called images and the css in the folder of css. When I apply the above restriction then the pages are not accessed and automatically it is redirected to the login page. This is the correct behavior that I want but the only issue is that my images and css also don't load. Hence my login page appears without css and images. Any help would be appreciated.
Manuel Schenkhuizen
Greenhorn

Joined: Apr 20, 2011
Posts: 14
i think you should show us what you write in your jsp .the <head> tag;
maybe the path of your css and images are not correct
perhaps a <interceptor> is a better solvement.
PrachiS Shah
Greenhorn

Joined: Sep 02, 2010
Posts: 10
My head portion contains just links for the css and images files..Like,
For the css;
<link rel="stylesheet" type="text/css" href="css/utility/base.css"/>

For the images;
<img src="images/xyz.jpg" alt="XYZ" title="XYZ" />

The images and css folders are present in the WebContent itself
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61066
    
  66

Page-relative URLs generally do not work in web apps. Use server-relative URLs that start with the context path. See the JSP FAQ for more information.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
PrachiS Shah
Greenhorn

Joined: Sep 02, 2010
Posts: 10
How can I give the context path? The context path is not going to be fixed.It depends upon the server on which it is deployed. All I need to do is to restrict the access of jsp pages till he logs in. I want to allow other resources i.e. images and css to be accessed anytime whether before of after login.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61066
    
  66

${pageContext.request.contextPath}
 
jQuery in Action, 2nd edition
 
subject: Resource Restriction using web.xml