How to map an html page in Spring MVC

Asked

Viewed 809 times

1

I have a Spring MVC project that will provide the Rest service to the front-end.
But when creating a page . html the project does not recognize it and always from 404. Is there any configuration I should do for spring mvc to recognize . html?

Servlet-context.xml file:

<beans:bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="/WEB-INF/views/" />
    <beans:property name="suffix" value=".jsp" /> /*ja mudei para .html mas não funcionou*/
</beans:bean>

And the web.xml file:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
  • Why the Pattern URL on web.xml is with only one "/" ?

  • Set as what the controller is calling this page.

  • Hello, in which folder is your HTML views?

1 answer

0

No use adding the . html extension in the InternalResourceViewResolver of Spring, as it is used to render files that need rendering Engines as is the case with JSP, in which case the configuration you need to add is this :

<mvc:resources mapping="/meusArquivosAssets/**" location="/meusArquivosAssets/" />

Browser other questions tagged

You are not signed in. Login or sign up in order to post.