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

本文介绍如何在使用EasyUI时,通过Java获取Webapp下的css资源,以实现在弹出窗口中选择图标的功能。内容涉及到从css加载图标样式,并提供了相关代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在使用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里显示,即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值