Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CSS displayed, CSS not displayed

 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20187
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20187
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That would be it. I have a 2.3 application. But the fix works just fine there.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic