• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Form authentication and CSS

 
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67645
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2907
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Rancher
Posts: 377
Android Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67645
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2907
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic