Announcement Announcement Module
No announcement yet.
@RequestMapping pointing to "/" Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • @RequestMapping pointing to "/"

    I appologize if this was asked before, but @RequestMapping term is very popular and it is very hard to find what I'm looking for on the forum - possibly I can't even name it

    In my Spring MVC project I've got a controller, where I've got the following method (no annotations except @Controller on the class):
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String home(Locale locale, Model model)
    	return "home";
    Unfortunately this won't get resolved correctly, when I type in my browser: http://localhost:8080/website/ (I get HTTP Status 404).

    If I use:
    @RequestMapping(value = "/home-page", method = RequestMethod.GET)
    public String home(Locale locale, Model model)
    	return "home";
    then if I browse to http://localhost:8080/website/home-page I'm good...

    Now, if I make the following change (remove: value = "/")
    @RequestMapping(method = RequestMethod.GET)
    public String home(Locale locale, Model model)
    	return "home";
    there's no more 404 error, but the page is broken, because all the links are wrong. E.g.
    HTML Code:
    <link href="/website/resources/css/styles.css;jsessionid=EA5D03D0894A03CF5DEF915402DA9359" rel="stylesheet" type="text/css" />
    instead of
    HTML Code:
    <link href="/resources/css/styles.css;jsessionid=EA5D03D0894A03CF5DEF915402DA9359" rel="stylesheet" type="text/css" />
    What am I doing wrong in mapping by using @RequestMapping?

    To be complete I attach my web.xml and application context:
    HTML Code:
    <web-app version="3.0" xmlns="" xmlns:xsi=""
    	xsi:schemaLocation="" metadata-complete="false">
    	<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    	<!-- Creates the Spring Container shared by all Servlets and Filters -->
    	<!-- Processes application requests -->
    HTML Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="" xmlns:xsi=""
    	<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
    	<!-- Enables the Spring MVC @Controller programming model -->
    	<mvc:annotation-driven />
    	<!-- Scan for annotation based controllers -->
    	<context:component-scan base-package="controllers" />
    	<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    	<mvc:resources mapping="/resources/**" location="/resources/" />
    	<!-- Configure Apache Tiles for the view -->
    	<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    		<property name="definitions">
    	<!-- Apache Tiles view resolver -->
    	<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    		<property name="requestContextAttribute" value="requestContext"/>
    		<property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
    	<!-- bean responsible for loading messages*.properties files for i18n internationalisation -->
    	<bean id="messageSource" class="">
    		<property name="basename" value="classpath:messages" />
    		<property name="defaultEncoding" value="UTF-8" />
    	<!-- beans helping to change current locale for i18n internationalisation -->
    	<!-- i18n 1.: change listener -->
    		<!-- Changes the locale when a 'locale' request parameter is sent; e.g. /?lang=de -->
    		<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
    			<property name="paramName" value="lang" />
    	<!-- i18n 2.: saves and reads cookies, where current (changed) locale is stored -->
    	<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
    		<property name="defaultLocale" value="en" />