aspose file tools*
The moose likes JSP and the fly likes CSS Style Looks Different Through JSP In Tomcat - Why? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "CSS Style Looks Different Through JSP In Tomcat - Why?" Watch "CSS Style Looks Different Through JSP In Tomcat - Why?" New topic
Author

CSS Style Looks Different Through JSP In Tomcat - Why?

Marcus Hathaway
Ranch Hand

Joined: Jun 07, 2005
Posts: 89
Hi everybody. I've created a JSP page that is styled by a CSS sytlesheet. This had been looking just perfect until i needed to run my application through Tomcat. Although the stylsheet is being found, some elements have stopped working. The fonts seem ok, as are all the colors and bording. However, the margins and i suspect padding has just gone awol. When before the page was nicely centered in the middle using the jello design, its now back over to the left and looking all out of sync. Could these problems be caused at all because Tomcat on its own is just a JSP/Servlet container and doesn't support certain style elements like a dedicated html server? Any advice or comments would be greatly appreciated.

Cheers!
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

No.

All CSS formatting is done by the browser.
The server (Tomcat or otherwise) does nothing but send a stream of text to the client.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Jason Moors
Ranch Hand

Joined: Dec 04, 2001
Posts: 188
The web browser renders the CSS not the servlet container.

When you say that it looked perfect before running on tomcat, do you mean your were running on a different web server or it was a static html page?

Most rendering problems (in particular padding) is due to syntax errors like and missing closed tag. A lot of browser handle invalid syntax but generate unpredictable results.

I would recommend checking/validating the generated html. I can't see it being a tomcat problem.

It might also be worth checking that you can access the CSS files from the browser by entering the URL in the browser. Is all your CSS is one file?

Jason

[ March 09, 2006: Message edited by: Jason Moors ]
[ March 09, 2006: Message edited by: Jason Moors ]
Marcus Hathaway
Ranch Hand

Joined: Jun 07, 2005
Posts: 89
Hi Ben, yes what you are saying makes sense. I've just been playing again and realise that actually.....if i run the site in mozilla through Tomcat it looks ok. Its only when i run the site through IE its goes funny. Why only when through Tomcat though? Does IE somehow read the page differently?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61430
    
  67

Do a View Source from the browser to compare the HTML files when sent by a means that works, and wnet sent by a means that doesn't.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Marcus Hathaway
Ranch Hand

Joined: Jun 07, 2005
Posts: 89
Hi guys, thanks for the amazing quick advice. I've solved the problem by removing my top line:

<?xml version="1.0" encoding="UTF-8"?>

Eveything "seems" to be working fine without this at the moment. I'm not sure why i've got that line there....its something i was taught to always include the last time i built a JSP site about 2 years ago at university.

I have this line at the top:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1.strict1-strict.dtd">

which obviously is telling the browser i'm using xhtml. This seems pretty obvious why it wasn't working....but just to confirm, that line i've removed...what was it for....and more importantly will i possibly need it further down the track!?
Jason Moors
Ranch Hand

Joined: Dec 04, 2001
Posts: 188
It seems from the WC3 website that you don't need the line, but it is encouraged.

An XML declaration is not required in all XML documents; however XHTML document authors are strongly encouraged to use XML declarations in all their documents. Such a declaration is required when the character encoding of the document is other than the default UTF-8 or UTF-16 and no encoding was determined by a higher-level protocol


http://www.w3.org/TR/xhtml1/

Not sure why the line defining that it's an xml file is causing the problem and I'm not an expert on xhtml, but I noticed that you are using the XHTML 1.0 Strict version, so I'm wondering if all your xhtml tags conform to the DTD.

My understanding is that xhtml is not as forgiving as html, therefore you always need an end tag. i.e in html you don't need a closing </br> but in xhtml you must adhere to the xml format and every tag must have an end tag.

You could try validating the xhtml at

http://validator.w3.org/

or you could try changing from Strict to Transitional

XHTML 1.0 Transitional
[ March 09, 2006: Message edited by: Jason Moors ]
Marcus Hathaway
Ranch Hand

Joined: Jun 07, 2005
Posts: 89
Hi Jason,

THanks for the link. I am trying to adhere to XHTML strict. I think i am including an XML declration though through my HTML tag of:

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

Perhaps the contradictory lines were to blame.

Thanks for all the help, got there in the end
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CSS Style Looks Different Through JSP In Tomcat - Why?