I have made a webpage in Servlet and now i want to add a stylesheet.css to it
Where should i exactly put the .css file ? like in ROOT of tomcat or some where else and what exact path i have to use??
link href='style.css' rel='stylesheet' type='text/css'
Thanks
Sundhas
Put the file somewhere in WebContent. There where your JSP files also are. Or did you abuse the Servlet to generate the HTML output? Well, at least, the public files needs to be placed in the WebContent folder. The folder name might differ from environment to environment, but it is at least the very same root folder where the WEB-INF folder resides. You normally place public content there.
Thanks EveryOne!
I figured this out
Well actually you don't have to paste the FILE.CSS in Root of tomcat
you actually have to paste the .css file where your netbeans Projects reside
for example C://Documents and settings/NetbeansProject/ProjectName/Web
Paste the .Css over there
and so this remains same : link href='style.css' rel='stylesheet' type='text/css'
~Sundhas~
Put your css into the webcontent folder. In the href provide an absolute link to the css and for html formatting use out.prinln statement.
Since you are using a relative path, it should be in the same location as your jsp. If you write your HTML in the Servlet, it should be placed in the root of the webapp.
Related
My bootstrap css file is located at
C:\Users\SCEA\Downloads\bootstrap-3.3.7\css
and for linking this to my php file I have given absolute path as:
<link href="C:\Users\SCEA\Downloads\bootstrap-3.3.7\css" rel="stylesheet">
but the effect of css is not visible.Is my css file not getting linked?
You might have a typo before css. The backslash before it might need to be a period.
<link href="C:\Users\SCEA\Downloads\bootstrap-3.3.7.css" rel="stylesheet">
If are running server in your local computer I suggest moving this file within the server document root.
Your comment:
css is a folder inside bootstrap-3.3.7
Probably in the CSS folder are the actual css files.
You need to refer to the actual CSS files and not to the folder itself.
Here is a quickfix using CDN:
Put these links in and it works guaranteed
Where should I put my css file if I have only one file (style.css) ?
I use sass for my project and I convert all my sass files to only one css file.
But I don't know where I have to put this file.. because normally I would create a static folder for each app but I think that makes no sense if I have only one file...
You just need to put the CSS file somewhere and tell HTML were to find using the link tag.
For example, if the file is in the folder "style" the tag will be.
<link rel="stylesheet" href="/style/file.css" />
Usually the main css style fail was in the root folder or in a style folder.
My pages in pretty basic html hold styling when kept in the root folder. Created a new folder for a group, but when I move pages to that folder they seem to lose connection to the css file.
Thought the problem might be the link since it now had to move up one folder. So I changed this:
link href="assets/css/readable/bootstrap.css" rel="stylesheet"
To this:
link href="http://www.example.com/assets/css/readable/bootstrap.css" rel="stylesheet"
but that changed nothing. Still page works fine in root folder, but not in /new folder.
Thank you for pointing out the basic premise I could be missing.
link href="/assets/css/readable/bootstrap.css" rel="stylesheet"
Add a / at the beginning of the path to refer to the Document Root instead of using a relative path.
In Eclipse, I created a Dynamic Web Project and a JSP file under WebContent folder. I also created a CSS file under the WebContent folder. Then I use <link rel="stylesheet" type="text/css" href="XXX.css"> in the JSP to link to the CSS file but when I run on web server (Tomcat) the CSS didn't apply. Can someone tell me why?
You must put your web project name before the address path of your css file
Example:
<link rel="stylesheet" href="/YourProjectName/XXX.css" type="text/css">
or in more dynamic way:
<link rel="stylesheet" href="${pageContext.request.contextPath}/XXX.css" />
Have fun :)
You can use: With style.css file in WEB-INF/jsp folder
<style type="text/css">
<%#include file="css/style.css" %>
</style>
NOTE
This however copies the entire source of the CSS file into the HTML
output of the JSP page. In other words, this is a server-side include,
not a client-side resource reference. So you effectively miss the
advantage that the browser can cache static resources and this way you
end up with a bandwidth waste because the very same CSS file is
embedded in every single page. In other words, a bad idea in terms of
performance and efficiency.
as #BalusC described in comment! you want to test your style.css file anyway, this is a solution.
you can use
<link rel="stylesheet" type="text/css" href="path/css">
You should restart eclipse so that it maps all css and javascript files again.
I worked for me.
Is it possible to get the site root relative translation in the CSS file of an MVC3 app?
In the .cshtml, I can use:
<link href="#Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
However, in the CSS I need to access content such as:
background-image: url('/Content/images/banner.png');
I would like to be able to get the root like i can with the #Url.Content so i can do something like this (which obviously doesn't work):
background-image: url(#Url.Content("~/Content/images/banner.png"));
Urls in css files are relative to the css file - it is not possible to specify the url relative?
If not then you will need to have ASP.NET process the file. You can either add a mapping to make all css files processed by the ASP.NET engine or to rename the css file into a file with with an extension that already is processed by ASP.NET - such as .aspx. You will probably also need a page directive to make it work...