This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread 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 Murach's Java Servlets and JSP this week in the Servlets 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: 60732
    
  65

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: 60732
    
  65

${pageContext.request.contextPath}
 
Don't get me started about those stupid light bulbs.
 
subject: Resource Restriction using web.xml
 
Similar Threads
Redirect to the requested page failed using form-based authentication
Security
Tomcat authentication and RACF
Context Path Still Won't Display an Image
Form Authentication not working