java web 项目图片显示

来源:互联网 发布:wan微型端口ip感叹号 编辑:程序博客网 时间:2024/05/22 03:27

我们在应用javaWeb程序的时候,有时候会调用本地的图片资源,或者是放在Tomcat容器下webapps文件下的资源,这时我们一定要应用绝对路径,要不然我们图片在浏览器上不予显示。绝对路径的书写方法是:

jsp中获取绝对路径的方法:String contextPath = request.getContextPath();//该方法是获取web程序的山下文路径。String path = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort() + contextPath;//request.getScheme(),是返回协议名称,request.getServerName(),返回服务器名称图片应该这样:<img src="<%=path%>/button/an-qd.gif" id="sub" style="cursor: hand" onclick="javascript:submitform();" width="51" height="23" border="0">

原创粉丝点击