您的位置:首页 > 移动开发 > WebAPP

Java获取Webapp下的css、js、image资源

2015-09-11 11:27 232 查看
在使用easyui时,有个需求,想要弹出一个框,可以选择图标,效果如下:



,实现的时候需要从css中加载以上的图标样式。其中,css样式如下:

.icon-loginpassword{background:url('IconsExtension/icon-password.png') no-repeat center center;}
.icon-loginuser{background:url('IconsExtension/icon-user.png') no-repeat center center;}
.icon-01{background:url('IconsExtension/01.png') no-repeat center center;}
.icon-1012333{background:url('IconsExtension/1012333.png') no-repeat center center;}
.icon-2012080111634{background:url('IconsExtension/2012080111634.png') no-repeat center center;}
.icon-2012080404218{background:url('IconsExtension/2012080404218.png') no-repeat center center;}
.icon-2012080404391{background:url('IconsExtension/2012080404391.png') no-repeat center center;}
.icon-2012080407553{background:url('IconsExtension/2012080407553.png') no-repeat center center;}
.icon-2012080412111{background:url('IconsExtension/2012080412111.png') no-repeat center center;}
.icon-201208041220{background:url('IconsExtension/201208041220.png') no-repeat center center;}
.icon-2012080412263{background:url('IconsExtension/2012080412263.png') no-repeat center center;}
.icon-2012080412301{background:url('IconsExtension/2012080412301.png') no-repeat center center;}
.icon-2012080412486{background:url('IconsExtension/2012080412486.png') no-repeat center center;}
.icon-2012080412511{background:url('IconsExtension/2012080412511.png') no-repeat center center;}
.icon-2012080412901{background:url('IconsExtension/2012080412901.png') no-repeat center center;}
.icon-2012081511202{background:url('IconsExtension/2012081511202.png') no-repeat center center;}
.icon-2012081511767{background:url('IconsExtension/2012081511767.png') no-repeat center center;}
.icon-2012081511913{background:url('IconsExtension/2012081511913.png') no-repeat center center;}
.icon-2012092109942{background:url('IconsExtension/2012092109942.png') no-repeat center center;}


代码如下:

String CSS_PATH = "/css/IconExtension.css";
String cssPath = request.getSession().getServletContext().getRealPath(CSS_PATH);
List<Icon> icons = new ArrayList<Icon>();
try {
BufferedReader reader = new BufferedReader(new FileReader(new File(cssPath)));
String str = null;
while ( (str = reader.readLine()) != null) {
int dotInd = str.indexOf(".");
int kInd = str.indexOf("{");
String className = str.substring(dotInd+1,kInd);
String img = "/css/" + str.substring(str.indexOf("'")+1, str.lastIndexOf("'"));
icons.add(new Icon(className,img));
}
} catch (Exception e) {
e.printStackTrace();
}
model.addAttribute("icons", icons);


最后,页面上获取List,动态组装成table,在一个弹出的window里显示,即可。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: