My web application is inside of a folder called application and inside my index.html I am providing the project path to the css file, but it gives me a 404 not found. Any ideas?
<link rel="stylesheet" type="text/css" href="application/css/style.css">
css folder and file style.css both exist and the css folder is located inside of application. This happens to all my files.
Related
I have created a simple Dynamic Web Project in Eclipse Mars, using Spring. My JSP is referring to a CSS file but css file is not getting pickup.
Eclipse Project Folder Structure:
enter image description here
Here is how, I referring it in my JSP:
My project structure is same as yours and I refer css file via:
href="css/anotherStylesheet.css"
Use this to add the css file
<link href="folder/styleFile.css" rel="stylesheet" type="text/css" />
It may also work when you drag and drop the CSS file directly to your page.
Configure the spring.xml and add the css folder in the configuration.Also check the eclipse deployment assembly (include the your webcontent floder)
I am not sure what is happening with that behavior but when :
i include the following script link in the HTML
<link href='./css/style.css' rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="./js/app.js"></script>
the page is not applying css or js if I just open the HTML page in any browser directly, but it runs on the server and apply the links
when i include the following instead of the pervious link
<link href='../static/css/style.css' rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../static/js/app.js"></script>
it Runs when open the Page in browser directly , but it is not applying when run on server
i can not figure out why this happening
The reason behind this is because when you run on the server, Spring boot maps the src/main/resources/static folder to your context root (usually /).
That means that if you have the following structure:
src/
main/
resources/
static/
myStyle.css
templates/
index.html
Both the src/main/resources/static/myStyle.css and the src/main/resources/templates/index.html will be available as /myStyle.css and /index.html.
If you're using Spring boot you should never include the static/ (or templates/) part in your links/references. You should never open the HTML page directly in your browser since this does not reflect any real environment.
To make it work locally you should run the Spring boot application and open the application through your browser, not just some HTML file in the project itself.
I started a new web project in Spring MVC 4(Spring Boot) and my question is where I must put my css files? I'm using thymeleaf template engine and my folder structure as in picture
as can u see, I trying create a CSS folder under the resources folder, but the link <link rel="stylesheet" href="/resources/css/main.css" /> from index.html is not working. any ideas?
Per the howto docs:
Spring Boot by default will serve static content from a folder called /static (or /public or or /resources or /META-INF/resources) in the classpath or from the root of the ServeltContext.
There's also a sample or two, e.g. this one.
Make sure you are packaging your project as a war in your pom.xml.
The /src/main/resources folder is usually deployed to WEB-INF/classes, so it won't be accessible directly from the context.
However, The /src/main/webapp is normally deployed to / (root of your web app), which is accessible from the context.
You should put your web resources under /src/main/webapp (e.g. /src/main/webapp/css). These are then automatically deployed under the context root of your web application. They are then accessible from e.g. /css.
<link rel="stylesheet" th:href="#{/css/main.css}" />
I'd also move your templates to /src/main/webapp/WEB-INF/templates.
If you read the SpringBoot documentation you will see that Spring Boot will automatically add static web resources located within any of the following directories:
/META-INF/resources/
/resources/
/static/
/public/
You have created folder named "css" and you put your file "main.css" inside this folder.
So you should use relative path when referencing this file inside your HTML
<link rel="stylesheet" href="/css/main.css" />
I've created custom 404 html page for Glassfish 3.1 in case of our application is down due to redeploy or some other failures.
But my 404.html doesn't want to search stylesheet and images files relative to its path (it is placed in domain1\docroot\ ). Every resource is searched in myApp context. That's far from what i want, since while redeploy there would be nothing in that location.
I've embedded styles into html, but this can't be done with images.
Storing images on other server would be to much trouble.
Is there a way to get to the docroot folder?
Finally I've created new application (DynamicWebProject in Eclipse) that contains just the files I needed in 404.html (and of course automatically generated META-INF, WEB-INF folders as well).
Then I've deployed it next to the primary application.
My 404.html file contains following reference to external resources:
<link rel="stylesheet" type="text/css" href="/myResourcesApp/style.css"></link>
Note the first slash "/" in href, which forces browser to search resource in the same domain where 404.html file is.
I got a PL/SQL Web Toolkit project not online (url : http://127.0.0.1:8080/dad/my_procedure).
And I just want to know how to import a local CSS file into this procedure...
I tried to do something like this :
htp.print('<link href="'C:/Users/Me/Desktop/css/filecss.css" rel="stylesheet" type="text/css" />');
or even
htp.print('<link href="/css/filecss.css" rel="stylesheet" type="text/css" />');
with no success...
In reality I don't know what's the root directory for a project like this.
The CSS file has to be within the HEAD area of the webpage. You should have your htp.print statement between the htp.headopen and htp.headclose calls.
Also, the CSS file path is relative to the web server processing the request, so the path should be to the directory on the web server that the CSS file resides.