title: Loading images/css/javascript in a jsp/java ee web application
body: <p>Today I just had my first class on Java ee and dynamic web project... and I have a question for you.</p>
  
  <p>My teacher asked us to create a controller in an very basic mvc concept. </p>
  
  <p>She gave us some code example and asked us to call a view from the controller. Ok, it works!
  But then, if I try to add an image <code>&lt;img src="images/img.jpg" /&gt;</code>, I think my controller re-route the folder images/img.jpg and well, my images/img.jpg is a type text in the file headers...</p>
  
  <p>Any help would be appreciated...</p>
  
  <p>Here is my servlet
  <strong>Controller.java</strong></p>
  
  <pre><code>package ca.qc.lacmegantic.ville;
  
  import java.io.IOException;
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  /**
   * Servlet implementation class Controller
   */
  @WebServlet("/Controller")
  public class Controller extends HttpServlet
  {
  private static final long serialVersionUID = 1L;
  
  /**
   * Processes requests for both HTTP &lt;code&gt;GET&lt;/code&gt; and &lt;code&gt;POST&lt;/code&gt;
   * methods.
   * 
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
  {
      String urlCP = request.getRequestURI();
  
      String url = urlCP.substring(request.getContextPath().length());
  
      if (url.equals("/") || url.equals(""))
      {
          request.getRequestDispatcher("WEB-INF/views/view.jsp").forward(request, response);
      }
  
  }
  
  /**
   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
   *      response)
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
  {
      processRequest(request, response);
  }
  
  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
   *      response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
  {
      processRequest(request, response);
  }
  
  }
  </code></pre>
  
  <p>Here is my <strong>web.xml</strong></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"
      version="2.5"&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;Controller&lt;/servlet-name&gt;
          &lt;servlet-class&gt;ca.qc.lacmegantic.ville.Controller&lt;/servlet-class&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Controller&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;session-config&gt;
          &lt;session-timeout&gt;30&lt;/session-timeout&gt;
      &lt;/session-config&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>Here is my <strong>view.jsp</strong></p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&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;title&gt;Hello World!&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt;Hello World!&lt;/h1&gt;
  &lt;img src="images/img.jpg" /&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Files Structure:</strong>
  <img src="https://i.stack.imgur.com/B9nwS.png" alt="Files Structure"></p>