Issue
Getting the following error in my console
printing ra
Dec 19, 2020 2:19:52 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound WARNING: No mapping for GET /FirstSpringWebExample/WEB-INF/hello.html
My files are as below, web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>FirstSpringWebExample</display-name>
<servlet>
<servlet-name>HelloWeb</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>HelloWeb</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
HelloWeb-servlet.xml
<beans xmlns = "http://www.springframework.org/schema/beans"
xmlns:context = "http://www.springframework.org/schema/context"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package = "com.sri.controller" />
<bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name = "prefix" value = "/WEB-INF/" />
<property name = "suffix" value = ".html" />
</bean>
</beans>
HelloController.java
package com.sri.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class HelloController {
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public String printHello(ModelMap model) {
model.addAttribute("message", "Hello Spring MVC Framework!");
System.out.println("printing");
return "hello";
}
@RequestMapping(value = "/hellot", method = RequestMethod.GET)
public String printHellos(ModelMap model) {
model.addAttribute("message", "Hello Spring MVC Framework!");
System.out.println("printing ra");
return "hello";
}
}
hello.html
<html>
<head>
<title>Hello Spring MVC</title>
</head>
<body>
<h2>${message}</h2>
</body>
</html>
Here in above code.Controller is working fine but view is not working.Here it is getting as requested resource not available.
Solution
I have changed the html extension to jsp extension.Now it is working (Dont know why InternalViewResolver cant render html page)
Answered By - Srinath Murugula