title: static resources and spring mvc
body: <p>I know there are many asked questions regarding this issue, but mine is different, I could not find any solution based on previous questions. I am using spring MVC and everything worked fine until i found out that my browser is not rendering the images. Then I tried to give my browser the full url to my images and it returned 404. I tried with 
  <code>&lt;mvc:default-servlet-handler/&gt;
   &lt;mvc:resources mapping="/images/**" location="/images/"/&gt;</code></p>
  
  <p>This did not get my images to display, but it also somehow messes up my controller, it is not handling the url mappings. I will show you most of my code.</p>
  
  <p>Here is my <strong>web.xml</strong>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"&gt;
  
  
  &lt;servlet&gt;
      &lt;servlet-name&gt;spring-brains&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;multipart-config/&gt;
  &lt;/servlet&gt; 
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;spring-brains&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;   
  &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;
          index.jsp
      &lt;/welcome-file&gt;
  &lt;/welcome-file-list&gt; 
  &lt;filter&gt;
      &lt;filter-name&gt;characterEncodingFilter&lt;/filter-name&gt;
      &lt;filter-class&gt;org.springframework.web.filter.CharacterEncodingFilter&lt;/filter-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;encoding&lt;/param-name&gt;
          &lt;param-value&gt;UTF-8&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;forceEncoding&lt;/param-name&gt;
          &lt;param-value&gt;true&lt;/param-value&gt;
      &lt;/init-param&gt;
  &lt;/filter&gt;
  &lt;filter-mapping&gt;
      &lt;filter-name&gt;characterEncodingFilter&lt;/filter-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;
  
  &lt;filter&gt;
      &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
      &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
  &lt;/filter&gt;
  &lt;filter-mapping&gt;
      &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;
  &lt;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;
          /WEB-INF/spring-brains-servlet.xml
      &lt;/param-value&gt;
  &lt;/context-param&gt;
  &lt;listener&gt;
      &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
  &lt;/listener&gt;
  &lt;jsp-config&gt;
      &lt;jsp-property-group&gt;
          &lt;url-pattern&gt;*.jsp&lt;/url-pattern&gt;
          &lt;page-encoding&gt;UTF-8&lt;/page-encoding&gt;
      &lt;/jsp-property-group&gt;
  &lt;/jsp-config&gt;
  </code></pre>
  
  <p></p>
  
  <p>Here is my <strong>spring-brains-servlet.xml</strong>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;context:component-scan base-package="bobi.spring.spring.brains"/&gt;
  
  &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"&gt;
      &lt;property name="viewClass" value="org.springframework.web.servlet.view.JstlView"&gt;&lt;/property&gt;
      &lt;property name="prefix" value="/"&gt;&lt;/property&gt;
      &lt;property name="suffix" value=".jsp"&gt;&lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;mvc:default-servlet-handler/&gt;
  &lt;mvc:resources mapping="/images/**" location="/images/"/&gt;
  
  &lt;security:debug/&gt;
  
  &lt;security:http pattern="/admin/login.jsp" security="none"/&gt;
  &lt;security:http auto-config="true"&gt;
      &lt;security:intercept-url pattern="/admin/**" access="ROLE_USER" /&gt;
      &lt;security:form-login login-page="/admin/login.jsp" default-target-url="/admin/admin.jsp" always-use-default-target="true"/&gt;             
      &lt;security:logout logout-success-url="/admin" /&gt;
  &lt;/security:http&gt;
  
  &lt;bean class="service.DummyUserService" id="user-service-bobi"/&gt;
  
  &lt;security:authentication-manager&gt;
      &lt;security:authentication-provider user-service-ref="user-service-bobi"&gt;
      &lt;/security:authentication-provider&gt;
  &lt;/security:authentication-manager&gt;
  </code></pre>
  
  <p></p>
  
  <p>and here is my <strong>AdminController</strong>:</p>
  
  <pre><code>/*
  
  
  * To change this license header, choose License Headers in Project Properties.
   * To change this template file, choose Tools | Templates
   * and open the template in the editor.
   */
  package bobi.spring.spring.brains;
  
  import domains.User;
  import java.io.IOException;
  import java.util.HashMap;
  import javax.servlet.ServletException;
  import javax.servlet.annotation.MultipartConfig;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.Part;
  import org.apache.commons.fileupload.FileUploadException;
  import org.apache.commons.fileupload.servlet.ServletFileUpload;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.CookieValue;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.servlet.ModelAndView;
  import service.Authentication;
  import service.ProductManager;
  import service.Service;
  
  /**
   *
   * @author BOBBOO
   */
  @MultipartConfig
  @Controller
  @RequestMapping(value = "/admin")
  public class AdminController {
  
  protected final Log logger = LogFactory.getLog(getClass());
  
  @RequestMapping(value = "/{adminview}")
  public ModelAndView getAdminView(@PathVariable("adminview") String view) {
  
      switch (view) {
          case "login": {
              return new ModelAndView("admin/login");
          }
          case "admin": {
              return new ModelAndView("admin/admin");
          }
          case "newcategory": {
              return new ModelAndView("admin/newcategory");
          }
          case "newproduct": {
              return new ModelAndView("admin/newproduct", "categories", Service.getCategories());
          }
          case "newuser": {
              return new ModelAndView("admin/newuser");
          }
          case "products": {
  
              return new ModelAndView("admin/products", "products", Service.getProducts());
          }
          default:
              return new ModelAndView("admin/login");
      }
  }
  
  @RequestMapping("/form")
  public void formHandler(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException, FileUploadException {
  
      String formId = request.getParameter("formId");
      request.setCharacterEncoding("UTF-8");
      if (formId != null &amp;&amp; formId.equals("newcat")) {
  
          service.Admin.saveCategory((HashMap) ServletUtils.prepareRequestArguments(request));
          response.sendRedirect("admin/newcategory");
      } else if (formId != null &amp;&amp; formId.equals("login")) {
          Authentication auth = new Authentication();
          User user = service.Service.getUser(request.getParameter("username"));
  
      } else if (formId != null &amp;&amp; formId.equals("newuser")) {
          Authentication auth = new Authentication();
          boolean success = auth.CheckUserName(request.getParameter("username"));
  
          if (success) {
              service.Admin.saveUser((HashMap) ServletUtils.prepareRequestArguments(request));
  
              response.sendRedirect("admin/newuser");
          } else {
              response.sendRedirect("admin/login");
          }
      } 
  
  }
  
  @RequestMapping(value = "/upload")
  public void productAdd(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException {
      if (ServletFileUpload.isMultipartContent(request)) {
  
          request.setCharacterEncoding("UTF-8");
          Part part = request.getPart("picture");
          String path = service.Constants.LINUX_ABS_PROJECT_PATH + System.getProperty("file.separator") + "images";
          Service serv = new Service();
          String kategorija = request.getParameter("category");
          System.out.println(kategorija);
          try {
              serv.SaveFile(path, part);
          } catch (Exception e) {
              e.printStackTrace();
          }
          ServletUtils util = new ServletUtils();
          try {
              service.Admin.saveProduct((HashMap) util.prepareRequestMultiPartArguments(request));
          } catch (Exception e) {
              logger.info("Error while saving product @ AdminController, line 92!!");
          }
  
          response.sendRedirect(request.getContextPath() + "/admin/admin.jsp");
  
      }
  }
  
  @RequestMapping(value="/edit/{object}/{objectId}")
  public ModelAndView editTable(@PathVariable("object") String editItemType, 
                                 @PathVariable("objectId") String itemId){
  switch(editItemType){
      case "product":{
          return new ModelAndView("admin/editproduct", "product", Service.getProduct(Integer.parseInt(itemId)));
      }
      case "category":{
      return new ModelAndView("admin/editcategory", "category", Service.getProduct(Integer.parseInt(itemId)));
      }
      case "user":{
      return new ModelAndView("admin/edituser", "user", Service.getProduct(Integer.parseInt(itemId)));
      }
  }
  return new ModelAndView("admin/admin");
  }
  
  @RequestMapping(value="/formedit")
  public void editForm(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException, FileUploadException {
  
      String formId = request.getParameter("formId");
      request.setCharacterEncoding("UTF-8");
      if (formId != null &amp;&amp; formId.equals("newcat")) {
  
          service.Admin.saveCategory((HashMap) ServletUtils.prepareRequestArguments(request));
          response.sendRedirect("admin/newcategory");
      } else if (formId != null &amp;&amp; formId.equals("login")) {
          Authentication auth = new Authentication();
          User user = service.Service.getUser(request.getParameter("username"));
  
      } else if (formId != null &amp;&amp; formId.equals("newuser")) {
          Authentication auth = new Authentication();
          boolean success = auth.CheckUserName(request.getParameter("username"));
  
          if (success) {
              service.Admin.saveUser((HashMap) ServletUtils.prepareRequestArguments(request));
  
              response.sendRedirect("admin/newuser");
          } else {
              response.sendRedirect("admin/login");
          }
      } 
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>So basically I have two questions:
  1. How to get my app to display static image content?
  2. Why and how is this --> </p>
  
  <pre><code>&lt;mvc:default-servlet-handler/&gt;
   &lt;mvc:resources mapping="/images/**" location="/images/"/&gt;
  </code></pre>
  
  <p>messing up my controller, or what I say stopping it from handling the mappings it is supposed to handle.</p>
  
  <p>Thank you in advance I have been struggling with this for days</p>