You error messaege tells No mapping found for HTTP request with URI [/addressbook/]
. In other words, you have not mapped a request mapping for the URL /addressbook
If you want your project to have a base URL as /addressbook
then change the web.xml as below
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
....
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/addressbook/*</url-pattern>
</servlet-mapping>
Controller
@Controller
public class HomeController {
@RequestMapping(value="/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
return "home";
}
}
Then goto the browser and type the below. There should be a /
at end.
http://hostname:port/addressbook/
But if you want to change the context root, you cannot do this by web.xml. Context root isn't part of the standard web.xml file. You can change this by doing the following in the eclipse
- In project properties click on
Web Project Settings
(assuming you are in a dynamic web project.) The only configuration value there is "Context root:"
- Change "Context root" to
/addressbook
- Change the web.xml url-pattern to
<url-pattern>/</url-pattern>
- rebuild
- remove the project from tomcat
- redeploy.
Quoted from digitaljoel