为什么我的外部css不能在子目录文件夹中工作?

时间:2015-03-13 02:42:28

标签: html jsp web.xml

我项目的文件是这样的:

  • 网页
    • WEB INF
      • 查看
    • CSS
    • 用户
      • account.jsp
      • error.jsp文件
      • 的login.jsp

视图文件夹中的所有jsp pages在浏览器中完全加载css。但它不适用于子目录 User 中的页面。而不是相对路径,我尝试了一个绝对的路径,它仍然没有工作......任何关于这个问题的根本原因的想法?一直试图弄清楚几个小时...另外如果它可以提供帮助,我最近对我的web.xml进行了更改...我怀疑它与它有关但却永远不知道...以下所有代码。< / p>

Account.jsp

<head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Site | <fmt:message key='UserAccount'/></title>
        <link rel="stylesheet" type="text/css" href="css/account.css">
        <link rel="stylesheet" type="text/css" href="css/header.css">
        <link rel="stylesheet" type="text/css" href="css/footer.css">  
    </head>

的Login.jsp

<head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Site | <fmt:message key='LoginRegister'/></title>
        <link rel="stylesheet" type="text/css" href="web/css/login_register.css">
        <link rel="stylesheet" type="text/css" href="web/css/header.css">
        <link rel="stylesheet" type="text/css" href="web/css/footer.css"> 
    </head>

error.jsp文件

<head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Site | Login Error</title>
        <link rel="stylesheet" type="text/css" href="css/login_register.css">
        <link rel="stylesheet" type="text/css" href="css/header.css">
        <link rel="stylesheet" type="text/css" href="css/footer.css"> 
    </head>

最近对web.xml的更改:

<jsp-property-group>
            <description>Handle the user console</description>
            <display-name>Jsp configuration for the user console </display-name>
            <url-pattern>/user/account.jsp</url-pattern>
            <url-pattern>/user/login.jsp</url-pattern>
            <url-pattern>/user/error.jsp</url-pattern>
            <include-prelude>/user/jspf/header.jspf</include-prelude>
            <include-coda>/user/jspf/footer.jspf</include-coda>
        </jsp-property-group>

    </jsp-config>
    <security-constraint>
        <display-name>Site User Administration</display-name>
        <web-resource-collection>
            <web-resource-name>Site User Administration</web-resource-name>
            <description/>
            <url-pattern>/user/*</url-pattern>
        </web-resource-collection>

        <auth-constraint>
            <description/>
            <role-name>siteUser</role-name>
        </auth-constraint>
    </security-constraint>


    <login-config>
        <auth-method>FORM</auth-method>
        <realm-name>file</realm-name>
        <form-login-config>
            <form-login-page>/user/login.jsp</form-login-page>
            <form-error-page>/user/error.jsp</form-error-page>
        </form-login-config>
    </login-config>


    <security-role>
        <description>Security for User</description>
        <role-name>mebzoneUser</role-name>
    </security-role>
</web-app>

2 个答案:

答案 0 :(得分:1)

使用绝对路径,尝试在路径中添加前导斜杠。

    <link rel="stylesheet" type="text/css" href="/web/css/login_register.css">
    <link rel="stylesheet" type="text/css" href="/web/css/header.css">
    <link rel="stylesheet" type="text/css" href="/web/css/footer.css"> 

如果您想要子目录中的相对路径,请使用..

从父目录开始
    <link rel="stylesheet" type="text/css" href="../css/login_register.css">
    <link rel="stylesheet" type="text/css" href="../css/header.css">
    <link rel="stylesheet" type="text/css" href="../css/footer.css"> 

答案 1 :(得分:0)

我的目录路径为Prod/bootstrap/style.css,我正在使用此路径

script src="bootstrap-3.3.4-dist/js/bootstrap.min.js"  type="text/css"

还试过这个,好吧

script src="~/bootstrap-3.3.4-dist/js/bootstrap.min.js"  type="text/css"

另外

script src="../bootstrap-3.3.4-dist/js/bootstrap.min.js"  type="text/css"

它正在处理放在主目录中的页面, 但是当我在子文件夹中使用页面时,CSS无法在客户端加载。

离。Prod/Modules/Example.aspx

请为此问题提供更好的解决方案。