Spring MVC ViewResolver not mapping to HTML files -


I can not get spring MVC to solve .html view files.

I have the following visual folder structure:

  Web-ANF-> View - | Home.jsp `- home.html  

I have a simple Hello World controller method which just prints the message and view name" home "back I have a home.jsp file , But instead use home.html.

  & lt ;! - Functional Mapping - & gt; & Lt; Servlet-mapping & gt; & Lt; Servlet-name & gt; Spacecraft & lt; / Servlet-name & gt; & Lt; URL pattern & gt; / & Lt; / URL pattern & gt; & Lt; / Servlet-mapping & gt; & Lt ;! - Work servlet reference - & gt; & Lt; Beam: Bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver" & gt; & Lt; Beans: Properties name = "prefix" value = "web-nf / view /" /> & Lt; Beans: Properties name = "suffix" value = ".jsp" /> & Lt; / Bean: beans & gt;  

When I hit SpiceShip / Home, then the controller halves print the World message and I see the home.jsp view without problems.

The problem is that when I change the suffix to .html

after the suffix and / or navigate home, the controller prints the message, though I see a 404 error in the browser And the console has the following: WARNING: No mapping was found for HTTP request with URI [/ Spaceships / WEB-INF / views / home.html]

To clarify:

  & lt ;! - Not working with .html - & gt; & Lt; Servlet-mapping & gt; & Lt; Servlet-name & gt; Spacecraft & lt; / Servlet-name & gt; & Lt ;! - I tried / without success here - & gt; & Lt; URL pattern & gt; / & Lt; / URL pattern & gt; & Lt; / Servlet-mapping & gt; & Lt ;! - Not working with .html - & gt; & Lt; Beam: Bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver" & gt; & Lt; Beans: Properties name = "prefix" value = "web-nf / view /" /> & Lt; Beans: Properties name = "suffix" value = ".html" /> & Lt; / Bean: beans & gt;  

I have checked in the Explosive War folder and can confirm that both home files exist.

Has anyone found something like this before?

The last part of the console message:

  INFO: Startup Hello server in 5256 MS server! 27 July 2014 12:52:01 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound Warning: No mapping was found for HTTP request with URI [/spaceships/WEB-INF/views/home.html] DispatcherServlet named ' Thank you for reading ' 

with spaceShips.

=========== Solution ============

The following (ugly) configuration solved the problem. Perhaps there are ways to clean it, but if you are experiencing the same problem then you can collect solutions from this.

Folder structure:

  Web -INF` -static | -HTML` -home.html | -css` -img  

Controller method:

  @RequestMapping (value = "/ home") public string goHome () {System.out.println ("Lolololololol"); Returned "static / html / home"; }  

Spring Config:

  & lt; Resource Mapping = "/ static / **" location = "/ WEB-INF / static /" /> & Lt; Beam: Bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver" & gt; & Lt; Beans: property name = "prefix" value = "" /> & Lt; Beans: Properties name = "suffix" value = ".html" /> & Lt; / Bean: beans & gt;  

See this for mapping HTML files in Spring MVC (details given in the answer to the step In simple:

In simple use to use static resources (html, css, img, js), a directory structure Use which looks like the following:

  src / package / layoutController.java WebContent / Web-ANF / static / html / layout.html Images / image.jpg css / test.css js / Main.js web.xml springmvc-servlet.xml @ Controller Public Square Layout Controller {@RequestMapping ("/ staticPage") Public String getIndexPage () {Return "Layout .htm"; }} & Lt ;! - in the spring config file - & gt; & Lt; Mvc: resource mapping = "/ static / **" location = "/ web-anf / static /" />  

layout.html

& lt; H1 & gt; Page with image & lt; / H1> & Lt; Img src = "/ static / img / image.jpg" />

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -