为什么我的外部 css 在子目录文件夹中不起作用



我的项目文件是这样的:

  • 网页
    • 网络简介
      • 视图
    • .CSS
    • 用户
      • 帐户.jsp
      • 错误.jsp
      • 登录.jsp

视图文件夹中的所有jsp pages都可以在浏览器中完美地加载css。但它不适用于子目录用户中的页面。我尝试了绝对路径,而不是相对路径,它仍然不起作用......知道这个问题的根本原因吗?几个小时以来一直试图弄清楚...另外,如果它有帮助,我最近对我的网络进行了更改.xml...我怀疑它与它有关,但永远不知道...以下所有代码。

帐户.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>

登录.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>

错误.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>

最近对网络.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>

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

    <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"> 

我的目录路径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

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

最新更新