title: Can't access CSS and JavaScript files in JSP
body: <p>I am developing a application in JSP/Servlet using MVC. In this application I want to load index.jsp as welcome page and this page retrieves the data from database. I did it. Now the problem is that when index.jsp page loads it fetches data from database but it shows it on browser as plain text and my CSS is not working for it. </p>
  
  <p>I know that during translation phase JSP is converted into servlet and after processing it send output to browser so during that we have to write the relative path of the .css files. I tried almost tutorials and questions in Stack Overflow but its not working. I tried <code>${pageContext.request.contextPath}</code> to retrieve context path but its not working. </p>
  
  <p>In this application my target is showing news updates on index.jsp page. So I am fetching data and showing it on JSP. To achieve this first controller runs and it fetch data from Database using DAO class. Then DAO Class returns that data into list to controller and controller then put data into RequestDispatcher and send it to JSP. Now when I am running application I get data on browser but it shows just plane text data not showing CSS effects. while when I set index.jsp as welcome page and from it when I type URL pattern then it shows fine but currently my welcome page is not set to any page and url-pattern is / so all that i need is performed well but CSS effects are not applied to output so how can I solve this it?</p>
  
  <p>Here I am posting Eclipse snap please give me suggestions.</p>
  
  <p>Directory Structure :</p>
  
  <pre><code>-MVCTest
     -src
     -build
     -WebContent
        -css
          -style.css
          -demo.css
        -js
          -jquery.js
  </code></pre>
  
  <p>Code of web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"&gt;
    &lt;display-name&gt;SwavaMVC&lt;/display-name&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
    &lt;servlet&gt;
      &lt;description&gt;&lt;/description&gt;
      &lt;servlet-name&gt;Visitor&lt;/servlet-name&gt;
      &lt;servlet-class&gt;controller.Visitor&lt;/servlet-class&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Visitor&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/asdfD&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>Code of servlet class:</p>
  
  <pre><code>package controller;
  
  import java.io.IOException;
  import java.sql.SQLException;
  import java.util.List;
  
  import javax.servlet.ServletException;
  //import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import model.NewsDAO;
  import model.classes.News;
  
  //@WebServlet("/Visitor")
  public class Visitor extends HttpServlet {
      private static final long serialVersionUID = 1L;
      public Visitor() {
          super();
      }
      @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
      {
          try {
              List&lt;News&gt; NewsList = NewsDAO.getNews();    
              request.setAttribute("NewsList", NewsList);
              request.getRequestDispatcher("index.jsp").forward(request, response);
          } 
          catch (SQLException e) {
              throw new ServletException("Cannot obtain news from DB", e);
          }
      }
      @Override
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      }
  }
  </code></pre>
  
  <p>This is the code of index.jsp file:</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%&gt;
  &lt;%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;System&lt;/title&gt;
  &lt;link href="css/style.css" rel="stylesheet" type="text/css" /&gt;
  
  &lt;link rel="stylesheet" href="css/main_slider.css" type="text/css" media="screen" charset="utf-8" /&gt; 
  
  &lt;script type="text/javascript" src="js/jquery-1.2.6.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="js/startstop-slider.js"&gt;&lt;/script&gt;
  
  &lt;link href="css/demo.css" type="text/css" rel="stylesheet"&gt;
  &lt;script type="text/javascript" src="js/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="js/jquery.scrollbox.js"&gt;&lt;/script&gt;
  
  &lt;script language="javascript" type="text/javascript"&gt;
  function clearText(field)
  {
      if (field.defaultValue == field.value) field.value = '';
      else if (field.value == '') field.value = field.defaultValue;
  }
  &lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body id="home"&gt;
  </code></pre>