spring mvc3+默认首页设置问题

web.xml配置:

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping> 

不要设置为*.do之类,这样只会拦截.do后缀名文件,设置为/,可以拦截所有请求。可以单独给页面设置后缀。如下java代码

然后java代码:

@Controller
public class IndexController {
    @RequestMapping("/")
    public String index(){
        return "/WEB-INF/html/login.html";
    }
  @RequestMapping("/index.do")
  public String index2(){
      return "/WEB-INF/html/login.html";
  }
  @RequestMapping("/index.html")
  public String index3(){
      return "/WEB-INF/html/login.html";
  }
}

controller后不要跟路径,就表示直接是根路径(不带最后斜杠http://localhost:8080/imageModel 个人理解)

然后:

http://localhost:8080/imageModel/

http://localhost:8080/imageModel/index.do

http://localhost:8080/imageModel/index.html

 以上都是默认首页。

controller设置路径:

@Controller
@RequestMapping("/invite")
public class InviteController {
    @RequestMapping("/getlist")
    @ResponseBody
    public List<Invite> queryList(){
        return biz.queryList();
    }
}

表示:http://localhost:8080/imageModel/invite/getlist

转载于:https://www.cnblogs.com/v-weiwang/p/4789632.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值