I am Java newbie.
What is the location of localhost?
I am placing my css file at this location
C:\Test Workspace\MyApp\cssFiles
Test Workspace is the name of my eclipse workspace.
In the jsp (in MyApp) where i am using the css file, i have written:
<link rel="stylesheet" type="text/css" href="/MyApp/cssFiles/BackgroundIMGE.css" media="screen">
But while running the application in chrome, error comes like this
GET http://localhost:8080/MyApp/cssFiles/BackgroundIMGE.css
http://localhost:8080/MyApp/cssFiles/BackgroundIMGE.css Failed to load resource: the server responded with a status of 404 (Not Found)
Maybe i am doing mistake in giving the correct location.
If you are using Eclipse, then you should keep your cssFiles folder just under MyApp/WebContent folder. After you build the project, the cssFiles folder should go directly under your web app root directory (MyApp).
Related
Cannot find the correct path for css that must be included to .jsp file.
The css files are in css folder and jsp is in folder "views" as shown in
this picture.
Have tried different paths to include it, but without result.
<link href="<c:url value="..." />" rel="stylesheet">
<link href="..." rel="stylesheet"/>
Could someone give information or correct path from .jsp file ?
Since WEB-INF folder is protected by server, you should move css & js folder to upper level, means css & js folder should exists in WebContent folder directly.
The structure should be like this:
-WebContent
-META-INF
-WEB-INF
-css
-js
The relationship between where files physically exist in project structure and where they are in runtime context is a classic problem (in my experience) with Java.
You could try using:
System.out.println(System.getProperty("user.dir"));
to find out the directory at runtime and use this to build a correct reference to your stylesheet.
you can use ./css/yourfilename as the path
./ means one up the current directory but the best way to do it is using the absolute path there are many advantage of using the absolute paths for example href="http:www.example.com/css/main.css" .
as meantioned by simon the web-inf could also be the problem
I try to add a CSS file to an JSP which is running on tomcat 8. The CSS just changes the appearance of tables. The CSS file is in the same folder as the JSP. I tried using:
<link href="table.css" rel="stylesheet" type="text/css">
but it didn't show any changes. So I tried:
<style type="text/css">
<%# include file="./table.css" %>
</style>
But this gives me a weird error, when I try to reach the page in my browser on the first try I get 404 - Resource not found but when I try again it works. What can cause this and is there an easier way to import my CSS file in the JSP? I use a servlet to reach the JSP if that matters.
Edit:// I just checked the WAR File i exported and the WEB-INF Folder only contains my classes the Folders of the HTML and JSP Sites are on the root directory of the WAR file.
I'd put all your .css files in a folder named /css right under the root of your WAR. The path would be css/table.css.
Same for JavaScript: create a folder named /js right under the root of your WAR. The path to JavaScript is js/foo.js
I have a css file in my WEB-INF folder and in a jsp page i have given the location of the css file as :
<link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/WEB-INF/Tabs.css"
But the problem is it doesn't link with the css file. If i take out the css file from the WEB-INF, it works perfectly.
This is my first time working with css.
What seems to be the problem here ?
Thank you for your time.
The problem here is just as you describe it, the location of the css-file.
All resources located within the WEB-INF-folder is not reachable directly from the web browser, but has to be accessed through a servlet.
And this is the reason of why the css isn't loaded when you are visiting your jsp.
Try instead to put them in a more common structure such as /webapp/resources/css/Tabs.css and change the href to ${pageContext.request.contextPath}/webapp/resources/css/Tabs.css
**Edit **
The folder I refer to as webapp might have any name, but the location of it would be the parent folder of the WEB-INF folder.
I'm creating a Play! 2.1.1 application which I have packaged into a war file using Play2War. This required me to add a context, application.context=/theApp/, in the application.conf file.
I deployed the WAR file to a tomcat7 server which resulted in the url localhost:8080/theApp/.
CSS/JS files load when the url is for example http://localhost:8080/theApp/thisseemstowork, but once the url is http://localhost:8080/theApp/thisoughttowork/180 none of the CSS/JS files are loaded. I simply get
GET http://localhost:8080/theApp/thisoughttowork/public/javascripts/vendor/bootstrap.min.js 404 (Not Found)
This is how I link to the js file in the views:
<script src="public/javascripts/vendor/bootstrap.min.js"></script>
This is in my routes file
GET /public/*file controllers.Assets.at(path="/public", file)
Anyone have an idea what I'm doing wrong? Let me know if you need any more info.
You need to use the Assets controller and reverse-routing.
<script src="#routes.Assets.at("javascripts/vendor/bootstrap.min.js")"></script>
This will generate the correct path no matter where you are in the app. As you can see from the routes file snippet you posted the path is relative to the /public folder, so this will work for any stylesheets, images, etc you put in there.
<link rel="stylesheet" href="#Assets.at("stylesheets/bootstrap.min.css")">
<link rel="stylesheet" href="#Assets.at("other/folder/styles.css")">
Here's Play's documentation:
http://www.playframework.com/documentation/2.1.1/Assets
Can anybody provide some instruction on how to setup a war file to show a favicon.ico in the browser address bar?
You can also use the following HTML markup in your HTML:
<link rel="icon" type="image/gif" href="/img/image.gif">
Most newer browsers should support it and I think it's generally a more clean way since you can use any image type/name/location you want.
This might be different in different application servers. For tomcat, the favicon comes from the directory your root context is mapped to. So if your application is mapped to the root context [/], just place the favicon.ico file in the top level folder in your war file.