用的Tomcat部署struts项目,在jsp中引用CSS。css文件在/css下。
  <head>
    <html:base/>
    <title>登录</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" href="/css/global-style.css" type="text/css">   </head>
不知道为什么没有起作用?网上的代码也都是这样,有没有人遇到过这种问题?

解决方案 »

  1.   

    /css表示从根目录起的文件目录。
    比如你的路径是:
    http://localhost:8080/
    那么这个/css文件目录是:http://localhost:8080/css
    如果你的路径是:http://localhost:8080/xy/
    那么你这个/css目录就还是:
    http://localhost:8080/css而不是http://localhost:8080/xy/css
    所以建议你使用相对路径。
      

  2.   

    struts使用外部CSS链接,有的时候确实会出问题。建议使用<%@ include%>标签来包含CSS外部文件。
      

  3.   

    确实是struts的问题。最好使用<%@ include%>标签来包含CSS外部文件可以解决问题。而且在用MyEclipse编辑CSS时提示用bgcolor,但用它在网页上就不起作用了,不知道是不是浏览器不支持的问题。struts的这些小问题太烦人了,唉,又耽误了一天。
    <style type="text/css"><!--
    <%@ include file="/css/global-style.css"%>
    -->
    </style>