Solon

问题:"/" 没有自动转到 "/index.html" ?

</> markdown

Solon 暂时不支持这种自动跳转,主要是这种场景越来越少了,感觉不值得为它查询两次。

有跳转的,需要自己处理一下:

1、路径转发(浏览器地址不变)

public class DemoController{
    @Mapping("/")
    public void home(Context ctx) {
        //在服务端重新路由到 /index.html (浏览器发生1次请求,地址不会变)
        ctx.forward("/index.html");
    }
}    

2、路径重定向(浏览器地址会变)

public class DemoController{
    @Mapping("/")
    public void home(Context ctx) {
        //通过302方式,通知客户端跳转到 /index.html (浏览器会发生2次请求,地址会变成/index.html)
        ctx.redirect("/index.html");
    }
}