0

Stylesheets not getting sent to browser.

Windows 7 Eclipse 4.5.2 (Dynamic Web project) tomcat 7.0.69 (instance is local to workstation)

[Eclipse workspace screen capture][1]

The web site is backed with servlets. I have tried... -- XHTML

out.println("<?xml-stylesheet href="/style/mystyle.css" type="text/css"?>");

-- XHTML

out.println("<?xml-stylesheet href="style/mystyle.css" type="text/css"?>");

-- Changing from XHTML to HTML

-- Using the

out.println("<base href=' http://localhost:8080/My_Website03/'>");

*(This method is not scalable to a server, I know.  Just trying things.)*

-- Using request.getContextPath()

out.println("<link rel='stylesheet' href='" + request.getContextPath()
        + "/style/style.css' type='text/css' />");
out.println("<link rel='stylesheet' href='" + request.getContextPath()
        + "/style/blue.css' type='text/css' />");

-- Using no leading forward slash

out.println("<link rel='stylesheet' href='style/style.css' type='text/css' />");

out.println("<link rel='stylesheet' href='style/blue.css' type='text/css' />");

-- Using a leading forward slash

out.println("<link rel='stylesheet' href='/style/style.css' type='text/css' />");

out.println("<link rel='stylesheet' href='/style/blue.css' type='text/css' />");

-- Using a leading dot slash

out.println("<link rel='stylesheet' href='./style/style.css' type='text/css' />");

out.println("<link rel='stylesheet' href='./style/blue.css' type='text/css' />");

-- Using a leading double dot slash

out.println("<link rel='stylesheet' href='../style/style.css' type='text/css' />");

out.println("<link rel='stylesheet' href='../style/blue.css' type='text/css' />");

And nothing works to get the .css files over to the browser.


In order to get servlets working the logging issue needed to be fixed and Eclipse had to be given control of the TomEE-Plume conf. I don't know why but fixing just one of the two would not correct the problem. My skills in Eclipse & TomEE are to weak to understand why.

Fixing the logging issue is written up on this wiki page. More information on: http://wiki.eclipse.org/WTP_Tomcat_FAQ#How_do_I_enable_the_JULI_logging_in_a_Tomcat_5.5_Server_instance.3F Even though the wiki section is written for Tomcat 5.5 it still applies to Tomcat 7.0.69. Long time for a bug to not get fixed if you ask me.

This http://tomee.apache.org/tomee-and-eclipse.html page, in the "Advanced installation" section, step 9, gives the impression that configuring for Eclipse to take control is optional. As said above, this step is not optional to get TomEE-Plume to work for servlets. I had to let Eclipse take control of the TomEE installation.

One more note on step 9. The instruction say "Use Workspace Metadata" but the option needed is called "Add External Web Module..." not "Use Workspace Metadata".

There is one last discrepancy to mention. There is no /webapps/tomee directory anymore. I guess this changed since the documentation was written. I used "\host-manager" instead. I hope this does not come back to bite me latter.

O, yea, one other thing, there is no "Save" button on the Web Modules or Overview pages. Do a CTL+S to save the changes.

Hope that helps others.

Xyz
  • 5,955
  • 5
  • 40
  • 58
paulhr
  • 339
  • 4
  • 17
  • What errors are returned by the web server on those requests? Does a plain non-generated HTML page work? – nitind May 25 '16 at 16:10
  • I have not been able to get Tomcat to produce logs other then the startup log that Eclipse shows by default. I changed the logging.properties with no effect. – paulhr May 25 '16 at 16:34
  • Did you map your servlet on an URL pattern of `/`? To exclude one and other, open those CSS files directly in webbrowser and check their output. – BalusC May 25 '16 at 16:54
  • Eclipse IDE shows a Servlet Mapping from / -> HomeServlet, but I don't see the mapping in the web.xml. Don't know where Eclipse is storing the mapping. – paulhr May 25 '16 at 17:01
  • There is the cause of your problem. Basically, you're overriding all requests which doesn't hit any specific servlet with `HomeServlet`. Those CSS files will represent the output of `HomeServlet`. Another way of mapping a servlet is `@WebServlet`. – BalusC May 25 '16 at 17:21
  • Fixed!!! Sweet. Thank you – paulhr May 25 '16 at 17:28
  • Please give a "Answer" so I can give you credit. – paulhr May 25 '16 at 17:30
  • I declared victory too soon. Works in the browser embedded in Eclipse but not on Firefox on the same workstation, but not embedded within eclipse. – paulhr May 25 '16 at 17:50
  • Another issue. Runs on Tomcat 7.0.69 (full content & CSS) but not TomEE_plume 1.7.4 (The requested resource is not available.) which is based on Tomcat 7.0.69. Ugh. – paulhr May 25 '16 at 18:02

2 Answers2

0

you should use the dev tools in your browser to investigate whether the line is actually getting printed to the html page or whether the css file is not able to be found. This can give you a better clue as to your error.

  • See original post. Added a screen capture that show the full html and the fact that there should be a css. – paulhr May 25 '16 at 16:49
-1

Try using Java to print your current location so that you check and make sure you are in the right working directory. Get current working directory in Java

Community
  • 1
  • 1
iHowell
  • 2,263
  • 1
  • 25
  • 49
  • This is not a standalone app. I don't see how getting the current working directory of the Tomcat server is going to tell me anything. Please clarify why this would matter. – paulhr May 25 '16 at 16:54
  • Because the directory could change and you could just be not hitting the style sheet. Which is actually pretty close to the actual issue described by your duplicate. – iHowell May 25 '16 at 18:17