0

I am trying to loading an external css page in my jsp page but the usual way of doing it doesnt help , Is there anything that am missing out ?

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">


 <title>Login Page</title>
<head>

    <link rel="stylesheet" type="text/css" href="style.css"/>
</head>
4
  • could you try passing the Url for style.css on browser and see if it comes up , i think the realtive path is not correct , is the style sheet in the same directory as of the JSP file Commented Apr 30, 2012 at 6:32
  • yes css it is in the same directory Commented Apr 30, 2012 at 6:37
  • were you able to open the CSS with browser ? Commented Apr 30, 2012 at 6:38
  • are u using any URL pattern(like we use for servlets) for the JSP page?If so then you need to specify the absolute path of external resources being used in page(images, css , js files ....) Commented Apr 30, 2012 at 6:39

1 Answer 1

2

The href in your link element specifes a URL-relative path that will only work if the css file is in the same folder as the JSP and if the JSP is directly addressed.

Since you have mentioned that css is in the same directory as JSP. Check how you are addressing JSP.

You need either to insert the context path to your webapp (e.g. /webapp/styles.css) or use a relative path or use the HTML <base> tag. It denotes the base URL of all relative URL's used in the final HTML output.

<head>
    <base href="${pageContext.request.contextPath}">
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <script type="text/javascript" src="js/script.js"></script>
</head>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.