My css import fails - html

stupid HTML question but I ve spent a lot of time trying to solve it.
I have difficulties to include some css files into a jsp page.
When I try:
<link href="<c:url value="/css/bootstrap.css"/>" rel="stylesheet">
And when I try:
<link href="<c:url value="/css/bootstrap.css"/>" rel="stylesheet">
server returns a 404 error and fails to import the file:
{code="404", msg="/css/bootstrap.css", uri=/css/bootstrap.css}
The text
" rel="stylesheet">
gets displayed on the web page.
The imports where at the top of the to avoid issues with previous lines.
The file is IS in /css dir
and I copied it in all possible places where it could be seeked to make sure.
So I m really puzzled...
Is there something obvious top that knocks somebody's bells?

I had forgotten to include this:
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
To make it work:
<link href="<c:url value="/css/bootstrap.css"/>" rel="stylesheet">

Maybe the use of single quotes inside double quotes will fix it.
<link href="<c:url value='/css/bootstrap.css'/>" rel="stylesheet">
Also, have you tried simply
<link href="../css/loginstyle.css" rel="stylesheet">
?

Related

Can't get my CSS Stylesheet in my HTML Sheet

I have my HTML file and my CSS file in the same folder, but I can still not find it using the following code:
<link rel="Stylesheet" href="style.css">
If I continue coding, it is stating that "Some content has been disabled in this document" as my program is stating. If I remove the code, it continues to work just normally. I do not know why this is happening, as I have made HTML and CSS programs before, and I was using the same technic.
Okay, so I found a solution. I normally can find my sheets easily using only the name of the file. But It did not work this time, so I did what fmsthird said, trying to put the exact path of my file instead. I totally forgot this feature, and it fixed it. I still do not know why I could not have done the other thing, and I spent 30 minutes trying to fix this.
The solution was so easy, and I totally forgot about it haha.
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="icon" type="image/png" href="favicon.png">
<title>Website Title</title>
</head>
<body>
</body>
</html>
you need to add the line into the head as displayed. Also it needs to add: type="text/css"

Can't get shortcut icon on title tab to show

I understand and have seen all the tutorials and stack questions about this but for some reason mine is not showing up!! im using ngrok to test this.
My image is in the assets/images/hello.ico directory. I dont think im inputting the path right. Im trying to use the hello.ico for my tab title.
<head>
<title> ScribeOwl</title>
<link rel="shortcut icon" href="/images/hello.ico"/>
</head>
What is the correct way to fill in the path if my image is in assets/images folder? thank you! Could turbolinks or anything else effect why this isnt working?
are you using erb? try this
<link rel="shortcut icon" href="<%= image_url('hello.ico') %>"/>
or just try with favicon_link_tag replacing your line with this
<%= favicon_link_tag 'hello.ico' %>
Try this
<link rel="icon" href="./assets/images/hello.ico?v=2" type="image/x-icon">

Including css and js files in a JSP not working

Hi I am facing a problem including js/css even image src in JSP files.
When my application starts with any context say abc ex. http://localhost:8080/abc and browser on a url ex http://localhost:8080/abc/reports/userCount and in that JSP i am including css as
<link rel="stylesheet" type="text/css" href="resources/thirdparty/css/jquery-ui.smoothness.min.css">
a 404 error is shown in browser console and the URL to download css is formed as
http://localhost:8080/abc/reports/resources/thirdparty/css/jquery-ui.smoothness.min.css
But when I am on on a page with URL like
http://localhost:8080/abc/createBadgeStep2
the same include to css works fine because url to download css is created fine.
http://localhost:8080/abc/resources/thirdparty/css/jquery-ui.smoothness.min.css
I can see clearly here that second slash after Context in the URL is creating problem. But can't figure out how to fix it. The problem goes for js and images too.
Any help will be highly appreciated.
Import your stylesheet as
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/resources/thirdparty/css/jquery-ui.min.css">
If you are importing several resources down the page, better set the context path in a page-scoped variable using the <c:set> JSTL tag.
<c:set var="ctxPath" value="${pageContext.request.contextPath}" />
Then use the variable in your href attribute.
<link rel="stylesheet" type="text/css" href="${ctxPath}/resources/..." />
You would also need to import the JSTL tag library to use the <c:set> tag.
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

Export JSP to Word With External CSS

I am trying to export a JSP generated document webpage to Microsoft Word. In the web browser, everything looks great. However, when I change
<%# page contentType="text/html; charset=utf-8" language="java" import="java.util.*, java.text.*;" errorPage="" %>
to
<%# page contentType="application/msword; charset=windows-1252" language="java" import="java.util.*, java.text.*;" errorPage="" %>
The page will try to open in word, but it will lose all of its styling.
I am linking to few external style sheets, but these are not picked up in the Word Document.
<link rel="stylesheet" type="text/css" href="css/common.css"/>
<link rel="stylesheet" type="text/css" href="css/general.css"/>
<link rel="stylesheet" type="text/css" href="css/headerfooter.css"/>
I have also tried linking href to the direct location on the server. This also did not work.
<link rel="stylesheet" type="text/css" href="http://localhost:8080/app/css/common.css"/>
<link rel="stylesheet" type="text/css" href="http://localhost:8080/app/css/general.css"/>
<link rel="stylesheet" type="text/css" href="http://localhost:8080/app/css/headerfooter.css"/>
Finally, I have tried to move the styling inside the JSP. However, this has not worked when it comes to exporting the document to word, either.
How can I export a JSP to Microsoft Word and have it retain styling?
Linking to external styling sheets will cause the JSP to lose formatting. The solution is to embed the styling inside the JSP. While I mention above that I did that, it contained formatting errors that, once fixed, displayed the styling properly in Microsoft Word.
Additionally, here is a good resource for adding Word specific styling to your document such as orientation, page margins, and embedded images:
http://sebsauvage.net/wiki/doku.php?id=word_document_generation

Store LINK elements and SCRIPT elements in a separate file

We may have to place lot of LINK elements and SCRIPT elements in the head elements of an HTML page. Also there can be a lot of pages with same above mentioned elements. Therefore can we put all the of them in a one file and place only that links containing file in HTML head element?
Eg: Something like,
<link href="links.something"> etc
instead of
<HEAD>
<link href="css/home.css" rel="stylesheet" type="text/css" media="screen" />
<link href="css/images.css" rel="stylesheet" type="text/css" media="screen" />
<link href="images/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<link href="css/smoothness/jquery-ui-1.9.2.custom.css" rel="stylesheet">
<script src="js/jquery-1.8.3.js"></script>
<script src="js/jquery-ui-1.9.2.custom.js"></script>`
<HEAD>
In your case it would be best to do PHP includes For example a page would be coded in parts: header.php, footer.php, and the main content would be loaded dynamically too.
<html>
<head>
<?php
include('header.php'); //PHP file that holds all the links(not anchor links) and scripts
?>
</head>
<body>
<?php
include('body.php?page=whatever');
include('footer.php');
?>
</body>
</html>
By doing so, you'd only have to edit one file to make changes to many.
You could generate them dynamically from a server-side script (say, PHP), I've sen this done using the CodeIgniter MVC framework, though you could do it with straight PHP.
You could also use a templating engine (like Smarty) to do the same thing.
Straight php:
<head>
include('js_files.php');
</head>
CI MVC (in the controller), this is fairly involve & there are much better examples on the web:
$jsfiles = $this->load->model('head_files');
$head = $this->load->view('head', $jsfiles, false);
I'm not sure about Smarty as I'm only starting in it myself, this is the main reason I started with it, unfortunately I've lost the link to the tutorial I saw.