0
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="css/font-awesome.css">

        <style type="text/css">
            body {
                background-image: url(man_meteor.jpg);
                background-repeat: no-repeat;  
                background-size: cover;
                background-attachment: fixed;
                background-position: center;
            }

Why is my background img not showing? Below is how my files are arranged. enter image description here

5
  • NB: content="text/html; charset=UTF-8" change to content="text/html" charset=UTF-8". Commented Jan 23, 2017 at 1:31
  • 1
    Wait a minute, where is the html file you're calling it from? Commented Jan 23, 2017 at 1:32
  • Working fine for me Commented Jan 23, 2017 at 1:32
  • does the link to your stylesheet work? If no, it's clearly a filepath issue (i.e. both that and your missing background image). Which file contains the code you posted? Commented Jan 23, 2017 at 1:53
  • The code is from home.jsp Commented Jan 23, 2017 at 2:23

2 Answers 2

1

As you suggest that your content is written inside a file called home.jsp, I suspect you are mapping "/" to one of your servlets which forwards your home.jsp to the client. This isn't right because this mapping will map every other resources to the same servlet that you use to forward your home.jsp. The correct mapping is to map "" instead.

One of your blocks in your web.xml should look like this instead:

<servlet-mapping>
    <servlet-name>The name of your servlet that forwards home.jsp</servlet-name>
     <url-pattern></url-pattern>
</servlet-mapping>
Sign up to request clarification or add additional context in comments.

1 Comment

OMG! you are a genius!
0

Seeing your code i can say that you need to specify height:200px OR height:400px example and next just for safety add double quotes like background-image: url("man_meteor.jpg");. Try this their are else other ways to get around.

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.