If i browse my site using http://localhost:8080/abc/Login/index.jsf, everything works fine. But if browse it using simply http://localhost:8080/abc, the page is shown but all its images and css files are missing. What can be the problem?
I have this in my web.xml :-
<form-login-config>
<form-login-page>/Login/index.jsf</form-login-page>
<form-error-page>/Login/index.jsf</form-error-page>
</form-login-config>
Probably, images are not getting referenced correctly. Can anybody help me?
I have referenced css file as follows :-
<link href="./Css/MainStyleSheet.css" rel="stylesheet" type="text/css" />
where Css is folder in Login
Your problem (as you guessed) comes from how you have referenced the CSS.
Probably the easiest way to fix it is to be more specific with your reference:
<link href="/abc/Login/Css/MainStyleSheet.css" rel="stylesheet" type="text/css" />
This reference should work regardless of where the calling file is in your directory structure.
Related
I have a web application developed in Java, and it is in Maven structure. I added the favicon.png to src/main/resources location and used the following tagline in JSP.
<head>
<link rel="icon" type="image/png" href="favicon.png"/>
</head>
But unfortunately the favicon is not visible. How can I fix this issue?
The favicon should be in your context root.
If you have src\main\webapp place it there, also if you want to load from classpath place it in src\main\resources\META-INF\resources
NOTE: If your application have context other than root (i.e. \) then you have to append it to the href.
I got a problem with load .css file, I put 'resources' in wrong folder probably and I dont know where I have to put it. How it should looks like? Here is a screen:
and I am loading css file like this:
<link rel="stylesheet" type="text/css" href="resources/css/flower.css" />
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 created Struts2 application using Maven. In this application I have created two namespaces, first is tc and the second one is cmpui. From the JSP page, I am trying to access .css files, but it is giving me 404 error.
Location of JSP page is :
webapp\tc\layout\stylesheets.jsp
Location of CSS file is :
WEB-INF\css\default.css
Code on JSP page is
<link rel="stylesheet" type="text/css" href="../WEB-INF/css/default.css">
Any suggestion please.
You can not access a resources that are under WEB-INF folder. Move your static resources to another place accessible by Struts2 (for example, web root). And use s:url tag to build the URL.
<link rel="stylesheet" type="text/css" href="<s:url value='/css/default.css'/>">
Actually when I run a particular JSP page it run perfectly(with external style sheet) but when servlet return back the control through RequestDispatcher, the page is not displaying properly means it don't took the css file path.
In my program the stylesheet is present inside css directory and the page is present inside another directory named JSP.
The code which include the css in the program is-
<link rel="stylesheet" href="../css/stylesheet.css" type="text/css"/>
Try URL-encoding your CSS file location. If you use taglibs, this might look something like:
<link href="<c:url value="/path/to/stylesheet.css"/>" rel="stylesheet"
type="text/css" />
where you define the path to the stylesheet from your app's web root.
If you want to use multiple stylesheets, you do something like:
<c:set var="stylePath" value="/path/to/cssFolder" />
...
<link href="<c:url value="${stylePath}/stylesheet.css"/>" rel="stylesheet"
type="text/css" />
Can you access the css url in the browser? You can create the full path using context path in jsp.(You can get the context path using request.getContextPath() in JSP)
May be you have to use <base/> html tag to resolve the relative path.
<head>
<base href="/testfolder/" />
<link rel="stylesheet" type="text/css" href="../css/stylesheet.css"/>
<link rel="stylesheet" href="<%=cssFilePath%>" type="text/css" />
Try this by declaring a String cssFilePath = "YOUR_CSS_FILE_PATH" in your jsp.