我的jsp没有看到css [英] my jsp doesn't see css

查看:212
本文介绍了我的jsp没有看到css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目结构:





hello.jsp:

 <%@ taglib prefix = curi =http://java.sun.com/jsp/jstl/core%> 
< html>
< head>
< title>标题< / title>
< meta charset =utf-8>
< link href =< c:url value =/ resources / myStyle.css/> rel =stylesheet>
< / head>
< body>
< h1>文字< / h1>
< p>文本。< / p>
< / body>
< / html>

myStyle.css:

  body {
font-family:Arial,Verdana,sans-serif;
font-size:11pt;
background-color:#f0f0f0;
color:#333;
}
h1 {
color:#a52a2a;
font-size:24pt;
font-family:Georgia,Times,serif;
font-weight:normal;
}
p {
text-align:justify;
margin-left:60px;
margin-right:10px;
border-left:1px solid#999;
border-bottom:1px solid#999;
padding-left:10px;
padding-bottom:10px;
}

有人可以解释我为什么css不工作吗?
我使用Intellij IDEA作为IDE和Tomcat。



这可以工作:

 < style> 
<%@ include file =/ resources / myStyle.css%>
< / style>


解决方案

所有这些都是相对路径相对于 webapp 文件夹。

 code>< link rel =stylesheettype =text / csshref =/ resources / myStyle.css> 

 c $ c>< link rel =stylesheettype =text / css
href =<%= application.getContextPath()%> /resources/myStyle.css>

 < jsp:directive.include file =/ resources / myStyle.css/> 






JSP - strong>



include指令中的文件名实际上是一个相对URL 。如果你只是指定一个没有相关路径的文件名,那么JSP编译器假定该文件与你的JSP在同一个目录下。



include指令用于包括档案。此指令告诉容器在翻译阶段将其他外部文件的内容与当前JSP进行合并。您可以在JSP页面的任何位置编写包含指令。


My project structure:

hello.jsp:

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
    <title>Title</title>
    <meta charset="utf-8">
    <link href="<c:url value="/resources/myStyle.css" />" rel="stylesheet">
</head>
<body>
<h1>Text</h1>
<p>Text.</p>
</body>
</html>

myStyle.css:

body {
    font-family: Arial, Verdana,  sans-serif;
    font-size: 11pt;
    background-color: #f0f0f0;
    color: #333;
}
h1 {
    color: #a52a2a;
    font-size: 24pt;
    font-family: Georgia, Times, serif;
    font-weight: normal;
}
p {
    text-align: justify;
    margin-left: 60px;
    margin-right: 10px;
    border-left: 1px solid #999;
    border-bottom: 1px solid #999;
    padding-left: 10px;
    padding-bottom: 10px;
}

Could someone please explain me why css doesn't work? I use Intellij IDEA as IDE and Tomcat.

This works though:

<style>
        <%@include file="/resources/myStyle.css" %>
</style>

解决方案

Simply try with any one. All these are relative path with respect to webapp folder.

<link rel="stylesheet" type="text/css" href="/resources/myStyle.css" >

OR

<link rel="stylesheet" type="text/css" 
                href="<%=application.getContextPath() %>/resources/myStyle.css" >

OR

<jsp:directive.include file="/resources/myStyle.css" />


JSP - The include Directive

The filename in the include directive is actually a relative URL. If you just specify a filename with no associated path, the JSP compiler assumes that the file is in the same directory as your JSP.

The include directive is used to includes a file during the translation phase. This directive tells the container to merge the content of other external files with the current JSP during the translation phase. You may code include directives anywhere in your JSP page.

这篇关于我的jsp没有看到css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆