Search code examples
spring-mvcweb.xmlwelcome-file

using controller mapped URL as welcome-file


In my controller:

@Controller
@RequestMapping(value="Main")
/*the methods */
 @RequestMapping(value="/index.do", method = RequestMethod.GET)

In my web.xml:

   <servlet-mapping>
      <servlet-name>MyController</servlet-name>
      <url-pattern>*.do</url-pattern>
   </servlet-mapping>
   <welcome-file-list>  
        <welcome-file>Main/index.do</welcome-file>  
    </welcome-file-list>

When I type : localhost/projectname/, it doesn't lead to localhost/projectname/Main/index.do as I expected, and has nothing output in the console of eclipse.

But if I try the whole URL localhost/projectname/Main/index.do, the controller is responding with what I want.

So how should I configure my welcome-file-list?


Solution

  • The <welcome-file-list> is composed of actual files, not URLs. So you cannot put Main/index.do in it. What you can do is to put a simple html file that does a redirect to index.do something like :

    <html xmlns="http://www.w3.org/1999/xhtml">    
      <head>      
        <meta http-equiv="refresh" content="0;URL='/Main/index.do'" />    
      </head>    
      <body> 
        <p><a href="/Main/index.do">Main page</a>.</p> 
      </body>  
    </html> 
    

    The body block should never be evaluated.