I have a problem with dynamically loaded CSS files in a JSF application running on tomcat 7.
If I load the CSS file on a static way like
<link href="mystyle.css" rel="stylesheet" type="text/css">
all is ok and the web page looks fine. But if I trying to load the CSS file dynamically like
<link href="#{pageManagerBean.getCSSFile()}" rel="stylesheet" type="text/css">
where pageManagerBean.getCSSFile() returns "mystyle.css", the CSS file will be not loaded. The browser gets from tomcat a "404 - Not found". But if I doing a browser refresh the CSS file is found and the web site looks fine.
Related
I m trying to create a sidebar where I have a style.css for customize it. When I inspect my page, it seems it never loads and get 404 not found.
<head>
<h1>sidebar</h1>
<title>Responsive Sidebar Menu</title>
<link rel="stylesheet" type="text/css" href="style.css"></head>
My project is structured like in the following picture:
I can't figure out how to write the path so it can load properly.
Move your template folder right under resources:
src/main/resource/static/css (for CSS files);
src/main/resource/templates (for HTML templates).
Then correct the link tag as follows:
<link href="../static/css/style.css" th:href="#{/css/style.css}" rel="stylesheet" />
I'm having a problem trying to access my static CSS resources from lower directories. If I am in the main directory it detects everything but if I go to other lower directories, it adds the path from that folder and does not detect them.
Error
(In that path "server" is a directory that should not appear, since css is in the main directory)
<link rel="stylesheet" href="/css/bootstrap.min.css">
<!-- Bootstrap CSS
============================================ -->
<link rel="stylesheet" href="/css/font-awesome.min.css">
I tried from putting ../, ./ searching the internet but I didn't find anything.
I am using Apache FreeMarker
Use .. to indicate the parent directory:
<link rel="stylesheet" href="../css/bootstrap.min.css">
<link rel="stylesheet" href="../css/font-awesome.min.css">
This will help you.
My file structure is as follows;
webapp
resources
foo.css
WEB-INF
home.jsp
mgr
ha.jsp
File home.jsp has the following:
<link rel="stylesheet" href="resources/foo.css
File ha.jsp has the following:
<link rel="stylesheet" href="../resources/foo.css
In Spring I have the following statement in my extension of WebMvcConfigurerAdapter:
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
Spring is happy and both JSP files render properly. But both JSP files cause errors with the Eclipse JSP editor because the editor cannot resolve the file locations. To fix the errors with the JSP editor I would have to code file home.jsp like
<link rel="stylesheet" href="../../resources/foo.css
And code ha.jsp like
<link rel="stylesheet" href="../../resources/foo.css
But this causes the web page to fail because Spring cannot resolve the files. So I tried coding in Spring the following:
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/","../../resources/");
This doesn't fix Spring but at least the JSP editor is happy. So how would I get out of the conflict and make both Spring and the JSP editor happy?
I read many possible explanations with this one being the best. Spring MVC mvc:resources location attribute
But I still could not get the problem resolved. Any help would be appreciated.
I am facing a problem in jsp-servlet, when I am setting up my index.jsp as welcome-file (default page to run first as soon as the project gets run) at that time the CSS and JS files are not rendered.
My project Hierarchy is like this
-ProjectName
-User
-css
-js
-index.jsp
And also when I run my project the URL in the browser will be localhost:8080/ProjectName so here index.jsp is called but without CSS and JS files.
Edit: Finally, I had solved this issue by copying the CSS and JS to the root directory also. i.e. I have CSS and JS # "User" as well as "ProjectName".
Try with the context path,
<link href="${pageContext.request.contextPath}/css/style.css" rel="stylesheet" type="text/css">
will get you the path of the css file in the css folder. or with the scriptlet,
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/style.css">
However, it is not recommended to you use the scriptlets in the jsp.
I want to keep all CSS files in one folder and I want to access them. Below is the path of my CSS folder
css/sampl.css. Where css is the folder.
This is my code:
<link href="/CSS/sampl.css" rel="stylesheet" type="text/css" />
I can't access the sampl.css file. Could somebody help me out?
You are missing a context path in the URL. To prepend a context path you can use JSP EL
<link href="${pageContext.request.contextPath}/CSS/sampl.css" rel="stylesheet" type="text/css" />
The CSS folder is in the web application root.