问题
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
This is my JSP code.
<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
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
回答1:
Probably the problem is path to your css file. First, try to remove your pages and css folder from your WEB-INF directory and put them next to WEB-INF. Then try this instead:
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/Login.css" />
回答2:
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.
Just an idea.
回答3:
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?
回答4:
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.jsp and your css file directory /WebContent/css/table.css
来源:https://stackoverflow.com/questions/29980538/css-not-working-in-jsp