JSP cannot find css and images - css

So, I have the classical problem described in the post title. In my jsp, I am trying to look for the css using this:
#import url(WebContent/css/adminstyle.css);
In order to help me diagnose the problem, I am trying to print on the jsp itself the value of what the above statement is resolving the url to. How can I get it
to print the value of:
#import url(WebContent/css/adminstyle.css)
I want to know what url the above statement in resulting in after it is evaluated.

Why you are using above statement to include css? You can use javascript statement to do your task.
<link rel="stylesheet" href="css/style.css" type="text/css" media="all">
Here i have style.css in css folder.
and even if you can find your images, you can find path to it or any file in project using,
String absolutePath = getServletContext().getRealPath("image.jpeg");
absolutePath can be used in img tag. Just put it in scriptlet.

Related

Parse .less files downloaded asynchronously

I'm using less for a web-app. In development environment, I have something like
<head>
<link rel="stylesheet/less" type="text/css" href="test.less"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/less.js/3.0.2/less.min.js" ></script>
</head>
this is working correctly: my test.less file is downloaded and converted into valid css by less, automatically.
Now, If the user navigate in a particular section of the site, I need to download another .less file. To do so, I create a element on the fly like this:
<link rel="stylesheet/less" type="text/css" href="test2.less"/>
and append it to the head.
This is NOT working - at least in Chrome 66.0.3359.117 - because the browser is not triggering the file download at all.
I resolved the problem by modifying the link 'rel' attribute:
<link rel="stylesheet" type="text/css" href="test2.less"/>
This way, the browser correctly download the file test2.less; however, it's content is not automatically parsed by less, so it is not converted to valid .css
I think that when less.js is downloaded, it executes by searchings all element with attribute rel = "stylesheet/less" and parsing them - stop.
But after then, it "stops" listening to other .less files downloaded asynchronously.
There is a way to "trigger" less parsing?
Thank you
Ok, so far I've found a solution.
I bet there are more efficient solutions, but for now I'll proceed this way.
I append the element
<link rel="stylesheet/less" type="text/css" href="test2.less"/>
in the head of the document, and this is not triggering the file download.
After that, I call the function
less.registerStylesheets().then(less.refresh);
This is causing less to read again the document, ask for all documents and parsing again them all... not efficient, but it works.
I wonder if exist a method to tell to less to import just a single file...
Edit: a small improvement:
instead of doing
less.registerStylesheets().then(less.refresh);
I can do
less.sheets.push(link);
less.refresh();
link is the reference to the link created. This way less won't read again all the document, searching for links; instead, it will just prepare the XHR for the new link created and parse that.

How to compile css file

I've seen this on a site:
<link rel="stylesheet" href="http://blablas.com/built/assets-styles.css?v=12355" />
which need to be underlined assets-styles.css?v=12355"
How to compile css file as above?
is it possible with less or sass?
[update]
And How about this?
<link rel="stylesheet" href="https://blablas.com/built/assets-201501-35b4b2bf0e75bb40f98d111b2d97951d.css">
CSS files are not to be compiled.
The reason the URI parameter is there could be it is not really a CSS file that's called, but a PHP engine (with mod_rewrite) that returns a CSS file based on the given parameter.
Another reason to use parameters is to force web browser to fetch the stylesheet again when necessary.
That has nothing todo with Compiling CSS! You use it for Cache Control. Everytime the CSS File gets changed they just need to change the numer and the new version gets requested.
In the 1st Link you posted ist a GET Variable therefore ist more likely to be vor some inernal Processing

dompdf Stylesheet Errors

So I am using https://github.com/chrisnharvey/CodeIgniter-PDF-Generator-Library/wiki to easily make PDF's on my system.
I am also using bootstrap. Now when I run the code, my styles dont' get extracted. And I get the following error:
Illegal string offset 'hex'
If I remove my stylesheets, I don't get the error but nothing is styled.
I am loading my styles like so:
<link href="http://the-green-panda.org/themes/admin/Adminica/css/bootstrap.min.css" rel="stylesheet" />
<link href="http://the-green-panda.org/themes/admin/Adminica/css/theme.css" rel="stylesheet" />
I did enable remote in the dompdf_config.inc.php file
def("DOMPDF_ENABLE_REMOTE", true);
Has anyone else used this codeigniter library and successfully linked style sheets to make the pdf's look nicer?

My jsp page doesn't see css styling

I know that there are many similar issues in google, but I can't find one that help me..
When I include a css file in my JSP page it doesn't work:
<link rel="stylesheet" type="text/css" ../../css/car_rental.css">
If I try this:
<%# include file="../../css/style.css"%>
it throws exception
/WEB-INF/view/../../css/style.css" file not found
How can I get rid of WEB-INF/view/ prefix?
P.S. my jsp page is located at /WEB-INF/view/ folder, and my css file at /css/ folder
It looks like you are referencing your style sheet via a server side include. The <%# include file="../../css/style.css"%> tag will inject the contents of the named file into the JSP containing the tag, as if it were copied and pasted. It is unlikely your JSP code will need to modify the contents of your cascading style sheet.
Try replacing the <%# include file="../../css/style.css"%> tag with the HTML tag to include your stylesheet.
<LINK href="/css/style.css" rel="stylesheet" type="text/css">
<%# include file="XYZ" %> statically includes the content of your file as part of compiled servlet response.
So even if it successfully finds the CSS file, its content will be treated as normal text and will be flushed in response.
This means that your page will simply display the content of CSS and there wouldn't be any styling that would actually occur
You need to use the link tag in the head. It directs the browser to apply the style.
Also, relative paths do not work in include, as you can see from the error.
Use:
<link href="../../css/style.css" rel="stylesheet" type="text/css">

Including CSS in MasterPages

I am new to the domain. I want to include a CSS file in my master pages,but it is not working can anyone try to help me out of this problem..
I give the link to the CSS externally as
<link href="Stylesheet1.css" rel="Stylesheet1" type="text/css" />
Is there any necessity to include CSS classes in master page if so how and where I have to include?
Try:
<link href="~/Stylesheet1.css" rel="Stylesheet1" type="text/css" />
Tilde (~) represent root directory.
If this doesn't work, if you can show us your directory structure, and look at the rendered source we can help more.
You can of course not use the Tilde (~) on tags that are not run server-side, what you have to do is something like this:
<link href="<%= ResolveClientUrl("~/Stylesheet1.css")%>" rel="stylesheet" type="text/css" />
Or just do a method that gives you back a full link-tag.
There's nothing wrong with the syntax of your <link> tag. The problem is likely to be caused by the fact that your CSS file isn't located at the URL you're attempting to get it from.
The href attribute in your markup specifies a file called Stylesheet1.css in the same folder as your master page. If its not you should specify the location of the stylesheet using standard, virtual path or move the stylesheet to the same folder as your masterpage.
More info.
http://w3schools.com/css/css_howto.asp

Resources