Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to load CSS file into jsp

Tags:

java

jsp-tags

I created a jsp page as follows:

<%@ page contentType="text/css" %> <html> <head> <title>Login page</title> <link href="/css/loginstyle.css" rel="stylesheet" type="text/css"> </head> <body> <h1> India welfare</h1> <p> welcome </p> </body> </html> 

and named it as login.jsp

and i also created a css file called loginstyle.css and the code of the .css file is as follows:

body { background-color:#d0e4fe; } h1 { color:orange; text-align:center; } p { font-family:"Times New Roman"; font-size:20px; } 

the directory structure for css and jsp's are as follows: webcontent/welfare_web/css for .css files and webcontent/welfare_web/login for jsp files

the programming editor is eclipse and the server i am using is tomcat 7.0. when i am trying to run the login.jsp file using tomcat server. The css file is not showing any effect. i mean the output is normal text and is not as per the CSS file.

please help me how to make the .css file to effect the jsp file.

like image 738
ylnsagar Avatar asked Sep 12 '11 01:09

ylnsagar


People also ask

Can we add CSS in JSP?

Well yes definitely you can. Consider JSP page as advanced HTML along with features of java. So surely you can use CSS in three ways: Inline CSS <h1 style="color:blue;"><%= someVariable %></h1>

Can we add CSS in Java?

Java objects are not HTML documents. The CSS2 syntax remains, so that a CSS editor can still be used to create the style sheet. However, the differences lead to adaptations of the CSS mechanism so that its power can be fully exploited and directed to some specific behavior.


1 Answers

css href link is incorrect. Use relative path instead:

<link href="../css/loginstyle.css" rel="stylesheet" type="text/css"> 
like image 192
Manny Avatar answered Sep 28 '22 05:09

Manny