CSS文件未加载? [英] CSS file is not loading?
问题描述
我有一个具有以下代码的JSP文件
< HTML&
< head>
< link rel =stylesheettype =text / csshref =../ CSS / home.css/>
< link rel =stylesheettype =text / csshref =../ CSS / left.css/>
< script type =text / javascriptsrc =../ js / friend_request.js>< / script>
< / head>
< body>
< div class =menu>
< form name =search_formmethod =post>
< table id =menutabelclass =color>
< tr>
< td class =alt>< A class =oneHREF =home.jsp>首页< / A>< / td>
< td class =alt>< A class =oneHREF =../ HTML / falbum.html>我的相簿< / A>< / td&
< td class =alt>< A class =oneHREF =../ HTML / MyDiary.html>我的日记< / A>< / td&
< td class =alt>< A class =oneHREF =../ HTML / MyFriends.html> Myfriends< / A>< / td&
< / tr>
< / table>
< / form>
< / body>
< / html>
当我在服务器上单独运行这个JSP文件时,CSS文件和Java脚本文件正确,但问题是当我从一个servlelt转发请求CSS和Java脚本文件不加载。任何人都可以帮我解决这个问题?
我有所有的html,jsp,CSS,java脚本到单独的文件夹。
喜欢
网页内容
|
| - HTML(此文件夹将包含所有HTML文件)
| --- CSS此文件夹将包含CSS文件)
| --- js
| --- JSP
使用HTML < base>
标记。它表示在最终HTML输出中使用的所有相对网址的基本网址。如果您使用 HttpServletRequest#getContextPath()
,那么您网页中的所有链接都将相对于 http://example.com/contextname
<!doctype html>
< html lang =en>
< head>
< base href =$ {pageContext.request.contextPath}>
< link rel =stylesheettype =text / csshref =css / style.css>
< script type =text / javascriptsrc =js / script.js>< / script>
< / head>
< body>
< ul>
< li>< a href =html / page.html> HTML网页< / a>< / li>
< li>< a href =jsp / page.jsp> JSP页面< / a>< / li>
< / ul>
< / body>
< / html>
请注意,您不应使用 /
,否则会导致域根,例如 http://example.com/yourlink
。
顺便说一下,链接不需要放置里面一个窗体。此外,HTML表应该仅用于表格数据,而不用于其他内容。 学习语义HTML 。
I am having a JSP file with the below codes
<HTML>
<head>
<link rel="stylesheet" type="text/css" href="../CSS/home.css" />
<link rel="stylesheet" type="text/css" href="../CSS/left.css" />
<script type="text/javascript" src="../js/friend_request.js"></script>
</head>
<body>
<div class="menu">
<form name="search_form" method="post">
<table id="menutabel" class="color">
<tr>
<td class="alt"><A class="one"HREF="home.jsp">Home</A></td>
<td class="alt" ><A class="one"HREF="../HTML/falbum.html">My Album</A></td>
<td class="alt" ><A class="one"HREF="../HTML/MyDiary.html">My Diary</A></td>
<td class="alt" ><A class="one"HREF="../HTML/MyFriends.html">Myfriends</A></td>
</tr>
</table>
</form>
</body>
</html>
When i run this JSP file individually on the server both the CSS file and the Java script file are loading correctly ,but the problem is when i forward the request from a servlelt both the CSS and the Java Script file is not loading. Can anyone help me out with this problem?
I am having all the html, jsp, CSS, java script into separate folders.
Like
Web-content
|
|-- HTML (This folder will have all the HTML files)
|--- CSS (This folder will have CSS files)
|--- js
|--- JSP
Make use of the HTML <base>
tag. It denotes the base URL of all relative URL's used in the final HTML output. If you set it with HttpServletRequest#getContextPath()
, then ALL links in your page will be relative to the http://example.com/contextname
URL, which is http://localhost:8080/Projectname
in your case.
<!doctype html>
<html lang="en">
<head>
<base href="${pageContext.request.contextPath}">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="js/script.js"></script>
</head>
<body>
<ul>
<li><a href="html/page.html">HTML page</a></li>
<li><a href="jsp/page.jsp">JSP page</a></li>
</ul>
</body>
</html>
Note that you should not start the relative URL's with /
, otherwise they will lead to the domain root, e.g. http://example.com/yourlink
.
By the way, links doesn't need to be placed inside a form. Also HTML tables ought to be used for tabular data only, not for other content. Learn semantic HTML as well.
这篇关于CSS文件未加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!