title: Spring MVC response output has no headers
body: <p>I set up a Java config Spring MVC web application but when I navigate to the home page, it outputs the raw page source.</p>
  
  <p>For example, I expect to see</p>
  
  <pre><code>Hello World!
  </code></pre>
  
  <p>But I see:</p>
  
  <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;html&gt;
      &lt;body&gt;Hello World!&lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>directly in the browser.</p>
  
  <p>Looking at the response, it looks like no response headers are being sent.</p>
  
  <p>Anyone know why?</p>
  
  <pre><code>public class WebInitializer implements WebApplicationInitializer {
  
      @Override
      public void onStartup(ServletContext sc) throws ServletException {
          WebApplicationContext context = getContext();
          sc.addListener(new ContextLoaderListener(context)); // attach WebApplicationContext to ServletContext life cycle
          ServletRegistration.Dynamic dispatcher = sc.addServlet("DispatcherServlet", new DispatcherServlet(context));
          dispatcher.setLoadOnStartup(1); // positive value means eagerly load on start up
          dispatcher.addMapping("/*"); // map DispatcherServlet to /* URL
      }
  
      private AnnotationConfigWebApplicationContext getContext() {
          AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
          context.setConfigLocation("com.example.app.config"); // package containing @Configuration object
          return context;
      }
  }
  
  @EnableWebMvc
  @ComponentScan(basePackages = "com.example.app") // base package to search for @Component / @Controller
  @Configuration
  public class WebMvcConfig extends WebMvcConfigurerAdapter {
  
      // set default servlet handler.
      // equivalent to &lt;mvc:default-servlet-handler/&gt;
      @Override
      public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
          configurer.enable();
      }
  
      @Bean
      public InternalResourceViewResolver getInternalResourceViewResolver() {
          final InternalResourceViewResolver resolver = new InternalResourceViewResolver();
          resolver.setPrefix("/WEB-INF/jsp/");
          resolver.setSuffix(".jsp");
  
          return resolver;
      }
  }
  
  @Controller
  public class MainController {
  
      @RequestMapping(value = "/", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
      public String main() {
          return "index";
      }
  
  }
  </code></pre>
  
  <p><strong>Edit:</strong></p>
  
  <p>It looks like when I remove the <code>&lt;%@page ...&gt;</code> line from the .jsp, the HTML displays properly. But that means that this JSP is not being parsed as a JSP but instead output directly as is to the browser...?</p>