您的位置:首页 > Web前端 > HTML

JFinal 访问指定url时,默认访问该url下的index.html

2015-11-26 13:36 671 查看
背景:使用arcgis的jsapi进行gis的开发

下载了arcgis的sdk(不能用 file://的方式直接访问 需要用http://的方式进行访问)

所以我把 sdk解压到了我的项目 project/WebContent/sdk 下

问题:因为sdk包含api和各种demo的示例。

arcgis在html里面写连接的时候不会写明 http://xxx/sdk/index.html 只写 http://xxx/sdk

由于JFinal对url进行了拦截,所以不能在访问http://xxx/sdk的时候访问到 http://xxx/sdk/index.html

经过一番的思索和JFinal爱好者的回答,写出了如下Handler来处理请求达到我想要的结果。

@Override
public void handle(String target, HttpServletRequest request, HttpServletResponse response, boolean[] isHandled) {
// 访问/sdk此路劲下的所有资源进行处理
if (target.contains("sdk")) {
// 如果访问的不是静态资源就进行拼接 拼接成xxx/index.html的方式
if (!target.contains(".")) {
// sdk为根目录 访问的时候跳转到/sdk/arcgis_js_api/sdk/index.html
if (target.equals("/sdk") || target.equals("/sdk/")) {
target = "/sdk/arcgis_js_api/sdk/index.html";
} else {
// 拼接url,使url成为 xxx/index.html的格式
if (target.endsWith("/")) {
target += "index.html";
} else {
target += "/index.html";
}
}
try {
response.sendRedirect(target);
} catch (Exception e) {
e.printStackTrace();
}
// 不加这句为什么会报 java.lang.IllegalStateException: Committed
isHandled[0] = true;
return;
}
}
nextHandler.handle(target, request, response, isHandled);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: