日期:2014-05-17 浏览次数:20643 次
<script type='text/javascript' src='resources/js/jquery-1.7.1.js'></script>
我把应用发布在app目录下。正常的访问路径应该是:http://localhost:8080/app/resources/js/jquery-1.7.1.js.
http://localhost:8080/app/something/resources/js/jquery-1.7.1.js,无法加载。
如果加上“/”,用绝对路径的写法:
<script type='text/javascript' src='/resources/js/jquery-1.7.1.js'></script>
http://localhost:8080/something/resources/js/jquery-1.7.1.js,同样无法加载。
<script type='text/javascript' src='<%=request.getContextPath()%>/resources/js/jquery-1.7.1.js'></script>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <script type='text/javascript' src=<c:url value="/resources/js/jquery-1.7.1.js"/>></script>
<head> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <base href="<%=basePath%>"/>
<script type='text/javascript' src='resources/js/jquery-1.7.1.js'></script>