1

How can I build a spring MVC app using pure html pages? When I deployed jsps on my tomcat 7 server, it is able to map the pages fine. But for html, the pages dont get displayed. I get 404 errors. How can I not use jsps in spring mvc? Please elaborate the steps I need to take.

Thank you in advance.

Horse Voice
  • 8,138
  • 15
  • 69
  • 120
  • 2
    There are a few suggestions in the answers [here](http://stackoverflow.com/questions/870150/how-to-access-static-resources-when-using-default-servlet) – GriffeyDog Oct 03 '13 at 20:36

3 Answers3

1

Thymeleaf will be your friend http://www.thymeleaf.org/

Nabil
  • 1,771
  • 4
  • 21
  • 33
1

In Spring MVC all request goes through FrontController - DispatcherServlet

There you need to tell Spring to allowe jsp and html both in your case

Example

dispatcher-servlet.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:p="http://www.springframework.org/schema/p"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xsi:schemaLocation="http://www.springframework.org/schema/beans           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

    <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>

    <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                <prop key="index.htm">indexController</prop>
            </props>
        </property>
    </bean>

    <bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          p:prefix="/WEB-INF/jsp/"
          p:suffix=".jsp" />

    <bean name="indexController"
          class="org.springframework.web.servlet.mvc.ParameterizableViewController"
          p:viewName="index" />
    <bean name="/*.htm" class="controller.MyController"/>
</beans>
Rahul Agrawal
  • 8,913
  • 18
  • 47
  • 59
  • I don't understand what this parameterizedViewController is all about. Also what's the deal with the bean name `"/*.htm"`? Can you please elaborate on your answer? I'm very new to spring. Please explain to me whats going on the xml you provided – Horse Voice Oct 05 '13 at 23:23
  • I was hoping for an explanation. Could you please advice? – Horse Voice Oct 11 '13 at 14:39
0

please change the view resolver suffix to .html,so that the viewResolver can able to render your view.