0

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?

ROROROOROROR
  • 959
  • 1
  • 14
  • 31

1 Answers1

0

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.

Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252
  • can one page do the redirect directly? even without fully loading the whole page? And there's no way to redirect to a controller method by the default context? – ROROROOROROR May 28 '14 at 18:05
  • @ROROROOROROR No the page has to be loaded by client browser, but almost all if not all browsers honour meta tags. So the browser loads the page, sees the meta refresh tag and immediatly loads the required URL without even displaying the body. – Serge Ballesta May 28 '14 at 18:12
  • thanks, it really works, without play the redirect page. But I don't know what would happen if this redirect file is charged in a bad network condition? – ROROROOROROR May 30 '14 at 14:59