aspose file tools*
The moose likes JSP and the fly likes CSS displayed, CSS not displayed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "CSS displayed, CSS not displayed" Watch "CSS displayed, CSS not displayed" New topic
Author

CSS displayed, CSS not displayed

Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

Hi.
I'm creating a Java web application and I'm facing the following problem.
My JSP pages use CSS to specify my desired style (font, color, links ...)
This application has login.jsp page , this page submits its form data to a servlet, if there is something wrong with the parameters, the servlet will forward the request to login.jsp in order to enter correct data.
Here is the structure :

JSP pages uses the followingl line :
<link href="../styles/web.css" rel="stylesheet" type="text/css" />
The problem is when login.jsp displayed for the first time, it displays the required effects of my CSS rules, but when it displayed again -through the forwarding process- it doesn't show the CSS effects.
It shows the effects if I put the css file in the same dir -admin dir- and chaneged the link element.
Well, I want to put my CSS files in a specific dir.
Any ideas ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61652
    
  67

That's because you are using a relative reference for the CSS url. The 2nd time around it's trying to find the location relative to the servlet -- which of course makes no sense.

Change the reference to an absolute one, and always do so for CSS, image and script references.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61652
    
  67

For your example, assuming JSP 2.0:



if still on JSP 1.2:



Note that you must include the context path in the references since the requests for the resources are inititiated by the browser and not made internally (such as a forward).
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18904
    
    8

This looked like a great way to have an absolute reference while still being able to run the JSP on a test server before going live with it. So I was quite dismayed when it didn't work. Fortunately there's a simple fix for the JSP 2.0 version:
[Edited to disable smilies - PC2]
[ December 28, 2005: Message edited by: Paul Clapham ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61652
    
  67

Under JSP 2.0 you should not have to use <cut> to emit the context path. If the raw EL is not evaluating, you may have a setup issue or your app is not defined as a 2.4 web app.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18904
    
    8

That would be it. I have a 2.3 application. But the fix works just fine there.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61652
    
  67

Tomcat (what you are using, I assume) will only enable the EL by default on your JSP pages for 2.4 web apps. So yes, for 2.3 apps you will need to use scriplet expressions or confine your use of the EL to JSTL tags.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: CSS displayed, CSS not displayed