gpt4 book ai didi

html - 为什么CSS效果只在JSP预览中出现,而在浏览器中不出现?

转载 作者:行者123 更新时间:2023-11-28 00:31:35 25 4
gpt4 key购买 nike

在我的 Java EE 应用程序中,我创建了一个 jsp 页面,如下所示:我正在创建一个以行显示航类的表格。航类位于“flight_list”请求属性下的“fList”列表中。

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="../../resources/css/styles.css"
type="text/css" />
</head>
<body>
<h1>List of Flights</h1>
<table>
<tr>
<th>From</th>
<th>To</th>
<th>Time</th>
<th>Price</th>
<th>Airplane</th>
<th>Seating</th>
<th>Number of Pilotes</th>
<th>Pilots names</th>
</tr>
<%
List<Flight> fList = (List<Flight>) request.getAttribute("flight_list");

for (Integer i = 0; i < fList.size(); i++) {
%>
<tr>
<td><%=fList.get(i).getFlightOrigin()%></td>
<td><%=fList.get(i).getFlightDestination()%></td>
<td><%=fList.get(i).getFlightTime()%></td>
<td><%=fList.get(i).getPrice()%></td>
</tr>
<%
}
%>
</table>

</body>
</html>

和styles.css如下

h1{
font-family: Trebuchet MS;
}

table {
display: block;
font-family: sans-serif;
-webkit-font-smoothing: antialiased;
font-size: 115%;
overflow: auto;
width: auto;
}
th {
background-color: #1e90ff;
color: white;
font-weight: normal;
padding: 20px 30px;
text-align: center;
}
td {
background-color: rgb(238, 238, 238);
color: rgb(111, 111, 111);
padding: 20px 30px;
}

在这里你可以看到我的元素结构

  1. WebContent-->WEB-INF-->views-->flights-list.jsp
  2. WebContent-->资源-->css-->styles.css

Project Structure

CSS效果只在eclipse中可见

CSS 文件仅在 JSP 预览选项卡上加载。问题是它们不会出现在浏览器上,除非我将 css 代码放在 <style>...</styles> . 中。

请帮助我在浏览器中正确加载页面。

最佳答案

使用下面的链接标签在 header 部分的 jsp 中加载/包含 .css/.js 文件

<head>
<link rel="stylesheet" href="resources/css/styles.css" type="text/css"/>
<script type="text/javascript" language="javascript" src="resources/javascript/foo.js"></script>
---
</head>

或者如果你想包含第三方 css/js 指定来自 url 的完整路径:

 <link rel="stylesheet" href="htts://..../foo.css" type="text/css"/>
<script type="text/javascript" language="javascript" src="htts://..../foo.css"></script>

关于html - 为什么CSS效果只在JSP预览中出现,而在浏览器中不出现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54383223/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com