Why Tomcat 6 did not find my .css styles

Trying to determine where / how to place stylesheets in a web application deployed in Tomcat 6 to allow .css styles. I have tried everything that I can think of without success.

I did these tests to find out to put the file, but few were successful.

1.) put css in-line with style attribute to verify text display green. 
    <div id="xxx" style="color:green;">  This worked.
    Then I removed the attribute and
2.) moved it into a in-file <style></style> stmt in the jsp.  This also worked. 
    I copied the css stmt into styles.css and disabled the in-line stmt in the jsp.
3.) added <link></link> stmts to file.  I tried several path refs to the file.
    And I put the file in several different directory locations to see where
    it would get resolved. (none were found)
        <link rel="stylesheet" type="text/css" href="styles.css">
        <link rel="stylesheet" type="text/css" href="css/styles.css">
        <link rel="stylesheet" type="text/css" href="/css/styles.css">

Using FireBug (css tab) I see the follow information for these links
  * <link rel="stylesheet" type="text/css" href="styles.css">
    this displays the src to index.html in the root dir

  * <link rel="stylesheet" type="text/css" href="css/styles.css">
    this displays the msg 
        Apache Tomcat/6.0.13 - Error report
        HTTP Status 404
        The requested resource () is not available.

  * <link rel="stylesheet" type="text/css" href="/css/styles.css">      
    this displays
        Failed to load source for: http://192.168.5.24:9191/css/clStyles.css

Contextual advertising / microblogging And the base path http://192.168.5.24:9191/microblog

Here is the test code I'm using.

I am using Spring 3. I have a simple JSP

- test.jsp -

    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <html>
      <head>
        <base href="<%=basePath%>">

        <link rel="stylesheet" type="text/css" href="styles.css">
        <link rel="stylesheet" type="text/css" href="css/styles.css">
        <link rel="stylesheet" type="text/css" href="/css/styles.css">
        <style> 
            #Yxxx {color:green;}
        </style>

      </head>

      <body>
        <div id="xxx">
            <h2>Test  <%=path%>  <%=basePath%></h2>
        </div> 
      </body>
    </html>

I placed the styles.css file in many directories to see where it can be resolved, but none of them were found.

In Tomcat 6, the expanded directory structure of nested web applications

    webapps/microblog
    webapps/microblog/styles.css
    webapps/microblog/index.html
    webapps/microblog/css/styles.css
    webapps/microblog/WEB-INF/css/styles.css
    webapps/microblog/WEB-INF/jsp/admintest/styles.css
    webapps/microblog/WEB-INF/jsp/admintest/test.jsp

So, how to get Tomcat 6 to resolve .css files?

+5
5

, CSS- . , . ( /microblog):

<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/styles.css">

, /WEB-INF . RequestDispatcher <jsp:include> JSP. /WEB-INF.

, , , URL / /*, .

+8

, , -.

html WebContent css-:

:

<link rel="stylesheet" type="text/css" href="css/style.css">

:

<link rel="stylesheet" type="text/css" href="/css/styles.css">

, ( Eclipse):

<link rel="stylesheet" type="text/css" href="myproject/css/styles.css">

, , :

<link rel="stylesheet" type="text/css" href="./css/styles.css">
+6

http://192.168.5.24:9191/microblog

    <link rel="stylesheet" type="text/css" href="styles.css">

http://192.168.5.24:9191/styles.css

    <link rel="stylesheet" type="text/css" href="css/styles.css">

http://192.168.5.24:9191/css/styles.css

    <link rel="stylesheet" type="text/css" href="/css/styles.css">

http://192.168.5.24:9191/css/styles.css

:

    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/styles.css">

:

    <link rel="stylesheet" type="text/css" href="<%=basePath%>/styles.css">

/WEB -INF ,

+3

It happened to me. I solved this by simply typing a space anywhere in the css file and saved it. The path should just be "css / style.css". It seems to me that sometimes Tomcat will not immediately recognize your file if this file (or the file path) is changed, for example, renamed or moved. The only way Tomcat can "implement" this change is to make some changes to the file and save it, and redeploying or updating would not help if it had not been done.

0
source

All Articles