设置web项目启动默认页面为controller方法

项目运行默认访问controller方法

方法一:

在默认页面index.jsp内加

<meta http-equiv="refresh" content="0; url=login">

方法二:

在controller类和该类方法上注解路径(“/”)

@Controller
@RequestMapping("/")
public class index {
  @RequestMapping(value = "/", method = RequestMethod.GET)
  public String index(Model model){
    return "index";
  }
}

web.xml文件配置

<welcome-file-list>
   <welcome-file></welcome-file>
</welcome-file-list>

方法三:

在mvc配置文件中配置

<!-- 定义无Controller的path<->view直接映射 -->
<mvc:view-controller path="/" view-name="redirect:login" />

在web.xml配置文件中配置

<welcome-file-list>
   <welcome-file>login</welcome-file>
</welcome-file-list>
发布了15 篇原创文章 · 获赞 3 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/BrotherBear2008/article/details/89024841