0 Replies Latest reply on Aug 18, 2014 6:45 AM by harish.rangaswamy

    Jboss AS 7.1 with spring mvc java config jsp file not rendering

    harish.rangaswamy

      I have created an project using maven and spring mvc using java config. The application is running but when i request the page, the jsp page is shown as it is(not compiled to html).

       

      The code is as below,

       

      public class BootStrapper implements WebApplicationInitializer {

       

       

        @Override

        public void onStartup(ServletContext servletContext)

        throws ServletException {

        AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext();

        webApplicationContext.register(AppConfig.class);

        webApplicationContext.setServletContext(servletContext);

       

       

        Dynamic dispatcherServlet = servletContext.addServlet("dispatcher",

        new DispatcherServlet(webApplicationContext));

        dispatcherServlet.addMapping("/*");

        dispatcherServlet.setLoadOnStartup(1);

       

        servletContext.addListener(new ContextLoaderListener(

        webApplicationContext));

        }

       

       

      @Configuration

      @EnableWebMvc

      @ComponentScan(basePackages = { "com.mahitijaala.product.controller" })

      public class AppConfig extends WebMvcConfigurerAdapter {

       

       

        @Override

        public void configureDefaultServletHandling(

        DefaultServletHandlerConfigurer configurer) {

        configurer.enable();

        super.configureDefaultServletHandling(configurer);

        }

       

        @Bean

        public UrlBasedViewResolver setupViewResolver() {

        UrlBasedViewResolver viewResolver = new UrlBasedViewResolver();

        viewResolver.setPrefix("/views/");

        viewResolver.setSuffix(".jsp");

        viewResolver.setViewClass(JstlView.class);

        return viewResolver;

        }

      }

       

       

      @Controller

      public class HomeController {

       

        @RequestMapping("/")

        public String index() {

        return "index";

        }

      }

       

      The output for the request,

      http://localhost:8080/mahitijaala/

      is

       

      <%@ page language="java" contentType="text/html; charset=UTF-8"

      pageEncoding="UTF-8"%>

      <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

      <html>

      <head>

      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

      <title>MahitiJaala | Home</title>

      </head>

      <body>

      <h2>Home Page</h2>

      </body>

      </html>