如何将CSS文件加载到jsp中 [英] how to load CSS file into jsp

查看:84
本文介绍了如何将CSS文件加载到jsp中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个jsp页面,如下所示:

I created a jsp page as follows:

<%@ page contentType="text/css" %>
<html>
<head>
<title>Login page</title>
<link href="/css/loginstyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<h1> India welfare</h1>
<p> welcome </p>
</body>
</html>

,并将其命名为 login.jsp

我还创建了一个名为loginstyle.css的CSS文件,.css文件的代码如下:

and i also created a css file called loginstyle.css and the code of the .css file is as follows:

body
{
background-color:#d0e4fe;
}
h1
{
color:orange;
text-align:center;
}
p
{
font-family:"Times New Roman";
font-size:20px;
}

css和jsp的目录结构如下: webcontent/welfare_web/css 用于.css文件和 webcontent/welfare_web/login 用于jsp文件

the directory structure for css and jsp's are as follows: webcontent/welfare_web/css for .css files and webcontent/welfare_web/login for jsp files

编程编辑器为 eclipse ,我使用的服务器为 tomcat 7.0 .当我尝试使用tomcat服务器运行login.jsp文件时. css文件未显示任何效果.我的意思是输出是普通文本,而不是根据CSS文件.

the programming editor is eclipse and the server i am using is tomcat 7.0. when i am trying to run the login.jsp file using tomcat server. The css file is not showing any effect. i mean the output is normal text and is not as per the CSS file.

请帮助我如何制作.css文件以影响jsp文件.

please help me how to make the .css file to effect the jsp file.

推荐答案

您可以这样写.这适用于每当您更改上下文路径时都不需要修改jsp文件的情况.

You can write like that. This is for whenever you change context path you don't need to modify your jsp file.

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

这篇关于如何将CSS文件加载到jsp中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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