html5 base标签的使用

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_43308851/article/details/86544655

今天在写后台管理系统的时候,出了一个错,图片怎么都加载不出来,后来经过调试发现了错误

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path+"/";
	response.getWriter().write(basePath);
%>


basePath最后的斜杠不能丢掉,丢掉之后会少一级目录,出现错误
测试代码`

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path+"/";
	response.getWriter().write(basePath);
%>






<!DOCTYPE html>
<html>
<head>
<base  href="<%=basePath%>"/>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
	function show(img)
	{
		
		/* var base = document.getElementsByTagName("base");
		alert(base[0].href); */
		alert(img.src);
	}
</script>

</head>
<body>
<h1 >标题</h1>
 <img  src="images/checkcode.png" onclick="show(this)"/>
</body>
</html>
展开阅读全文

没有更多推荐了,返回首页