java CSS 在 JSP 中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29980538/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 16:13:06  来源:igfitidea点击:

CSS not working in JSP

javahtmlcssjspservlets

提问by Craig

I am just trying to add some simple css to my JSP page. My jsp page is located in the following directory; WebContent > WEB-INF>pages>Login.jsp | My css file is located here; WebContent > WEB-INF > css > Login.css

我只是想向我的 JSP 页面添加一些简单的 css。我的jsp页面位于以下目录;WebContent > WEB-INF>页面>Login.jsp | 我的 css 文件位于这里;WebContent > WEB-INF > css > Login.css

This is my JSP code.

这是我的 JSP 代码。

<head>
<link rel="stylesheet" type="text/css" href="../css/Login.css" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login Page</title>
</head>
<body>
    <div>
        <form method="post">
            <table>
                <tr>
                    <td>
                        //some code
                    </td>
                </tr>
                <tr>
                    <td>
                        //some code
                    </td>
                </tr>
                <tr>
                    <td>
                        //some code
                    </td>
                </tr>
            </table>
        </form>
    </div>
</body>

and this is my CSS

这是我的 CSS

table {
    border-width: 1px;
    border-color: black;
    border-style: solid;
}

I just wanted to make a border show around the table to see if it would work and it's not. There is no border around my table what so ever.

我只是想在桌子周围做一个边框展示,看看它是否有效,而事实并非如此。我的桌子周围没有任何边界。

Any idea why this may not be working

知道为什么这可能不起作用

回答by hamed

Probably the problem is path to your css file. First, try to remove your pages and css folder from your WEB-INFdirectory and put them next to WEB-INF. Then try this instead:

问题可能是您的 css 文件的路径。首先,尝试从您的WEB-INF目录中删除您的页面和 css 文件夹,并将它们放在WEB-INF. 然后试试这个:

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

回答by Tango199

If you are using the tomcat plugin through eclipse, try and right click on the server and press clean. I had this issue and it was because the css file wasnt getting updated by the server. By doing a clean it updates all of the files.

如果您通过 eclipse 使用 tomcat 插件,请尝试右键单击服务器并按 clean。我遇到了这个问题,这是因为服务器没有更新 css 文件。通过进行清理,它会更新所有文件。

Just an idea.

只是一个想法。

回答by damon

just copy and past your both folder into web content and change path link rel="stylesheet" type="text/css" href="../css/Login.css"
your directory just like /WebContent/pages/Login.jspand your css file directory /WebContent/css/table.css

只需将您的两个文件夹复制并粘贴到 Web 内容中,然后link rel="stylesheet" type="text/css" href="../css/Login.css"
像更改/WebContent/pages/Login.jspcss 文件目录一样更改您的目录路径 /WebContent/css/table.css

回答by eToi

You can check what "../" resolves to using your browser. You might need to use "./" instead.
In your browser open developer tools (In chrome press F12) then go to the network tab. Browse to your page normally and watch the outgoing requests. You should see the request for your Login.css stylesheet. Hover over it to see the complete path it is using. Is this the correct path?

您可以使用浏览器检查“../”解析的内容。您可能需要改用“./”。
在您的浏览器中打开开发人员工具(在 Chrome 中按 F12)然后转到网络选项卡。正常浏览到您的页面并查看传出的请求。您应该会看到对 Login.css 样式表的请求。将鼠标悬停在它上面以查看它正在使用的完整路径。这是正确的路径吗?