I am new to Spring framework. I would to develop a simple web-app that displays a hello.jsp content based on url "/greeting.html". But now, it gives me 404 error. What am I doing wrong?
Here is the github repo for my project (this project was created under Eclipse STS): https://github.com/terancet/EventTracker
Here is my HelloController class
@Controller
public class HelloController {
@RequestMapping(value = "/greeting")
public String sayHello(Model model) {
model.addAttribute("greeting", "Hello World");
return "hello.jsp";
}
}
Here is web.xml
<servlet>
<servlet-name>springDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.pluralsight.WebConfig</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map all requests to the DispatcherServlet for handling -->
<servlet-mapping>
<servlet-name>springDispatcherServlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
Here is a project structure:
add a log4j.xml or log4j.properties into the
folder (it will automatically be detected). Then when you start up the server it will tell you exactly where the url mapping is for your controller via info log. This is important not to only verify the mapping url but to make sure it is actually being mapped:
Also, in STS/Eclipse if you:
by default that is where the url path is derived. So if the context-root value in there is: 'EventTracker' then your full url request will be (assuming a '.jsp' suffix is set as others have indicated in your resolver):
Sample log4j.xml from 1 of my projects:
log info: