The Nightmare
The Nightmare

Reputation: 701

HTML page and Spring

I create Simple MVC project in Spring. Defaultr generic a jsp pages. I try change jsp to html and i:

<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="/WEB-INF/views/" />
    <beans:property name="suffix" value=".jsp" />
</beans:bean> 

replace this:

<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="/WEB-INF/views/" />
    <beans:property name="suffix" value=".html" />
</beans:bean>

and create html page in views folder, but after changes and try run i have this error:

WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/myapp/WEB-INF/views/home.html] in DispatcherServlet with name 'appServlet'

Why i have this error? I only change jsp to html.

Upvotes: 0

Views: 629

Answers (1)

Ralph
Ralph

Reputation: 120881

The InternalResourceViewResolverdoes not forward the request to the view folder. Instead it is responsible for selecting the 'jsp' (or what ever) according to the return value of an Controller(Method). Like

@RequestMapping("home")
public ModelAndView controllerMethodForHome(){
     //will render /WEB-INF/views/homeView.html
     return new ModelAndView("homeView");
}

with:

<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
   <beans:property name="prefix" value="/WEB-INF/views/" />
   <beans:property name="suffix" value=".html" />
</beans:bean>

will return the /WEB-INF/views/homeView.html for localhost:8080/myApp/home


Maybe the thing you want to use is the static resource mapping

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

Have a look at this question/answer for an example

Upvotes: 2

Related Questions