Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Form authentication and CSS  RSS feed

 
Bai Shen
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using form authentication for my web application. My login page links to my CSS file the same as my other pages. But for some reason it completely ignores the CSS.

Is this part of the form auth, or is there something else I should look at?

TIA.
 
Bai Shen
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, if I go directly to the login page url, the CSS works correctly. It's only when I'm forced there through the security constraint.

They page and the css are both in the same directory.
 
Bai Shen
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fixed it. Had to put the full context path to the css, even though the login jsp was in the same directory.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bai Shen wrote:Fixed it. Had to put the full context path to the css, even though the login jsp was in the same directory.
This is something you should always do in a web application.
 
salvin francis
Bartender
Posts: 1479
21
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
Bai Shen wrote:Fixed it. Had to put the full context path to the css, even though the login jsp was in the same directory.
This is something you should always do in a web application.


I dont understand, are you suggesting we use absolute urls as opposed to relative urls for CSS in a website ?
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

Yes you should probably be using the absolute URL.

Typically you would have all your JSPs stored within the WEB-INF folder and only be accessing them through forwarded requests from servlets.
Because of this you would not be able to give a relative URL to the CSS. So you would need to use an absolute URL.

You can use a core taglib <c:url value="/css/style.css"/> which would give you the absolute URL from the root of the webapplication.

Sean
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sean Clark wrote:Hey,

Yes you should probably be using the absolute URL


No, you should not use absolute URLs.
If you do, you will need to update them every time your domain changes.
You should make your URLs relative to the root of the web application, including the contextPath.
See:
http://faq.javaranch.com/java/RelativeLinks
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben Souther wrote:

No, you should not use absolute URLs.
If you do, you will need to update them every time your domain changes.
You should make your URLs relative to the root of the web application, including the contextPath.
See:
http://faq.javaranch.com/java/RelativeLinks


Please excuse I think we were at cross purposes, when I said absolute I mean absolute relative to the contextPath.

for example: <c:url value="/css/style.css"/>
gives the absolute URL (relative to the contextPath) /contextPath/css/style.css

Sean
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Absolute URL: http://www.domain.com/contextpath/servletpath/pathinfo
Server-relative URL: /contextpath/servletpath/pathinfo
Context-relative URL: /servletpath/pathinfo
Page-relative URL: ../whatever.xyz

Server-relative URLs are what should be used for client-accessible resources such as CSS and JavaScript and image files.
 
salvin francis
Bartender
Posts: 1479
21
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ye server relative urls seems right...

as a practical usecase, try saving a website with absolute urls to your pc and then check it when offline...
there was this site i once saved where everything (images,css, etc.) was absolute and when i saw the copy offline ... it seemed naked
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!