[英]Script tag not working
I am creating an application using spring and tiles. 我正在使用spring和tile创建一个应用程序。 I have a general template where all the js and css are loaded.
我有一个通用模板,所有js和CSS都已加载。 Anyway, there are some script that are only needed on some views, so I put them only where I need them.
无论如何,有些视图只在某些视图上需要,所以我只将它们放在需要的地方。 But it doesn't work
但这不起作用
there are some code 有一些代码
general-template.xml general-template.xml
<tiles-definitions>
<definition name="template.general" template="/WEB-INF/view/templates/general.jsp">
<put-list-attribute name="styles">
<add-attribute value="/media/css/materialize.css" />
<add-attribute value="/media/css/style.css" />
<add-attribute value="/media/css/custom-style.css" />
</put-list-attribute>
<put-list-attribute name="scripts">
<add-attribute value="/media/js/jquery-1.11.2.min.js" />
<add-attribute value="/media/js/materialize.js" />
<add-attribute value="/media/js/plugins/perfect-scrollbar.min.js" />
<add-attribute value="/media/js/plugins.js" />
</put-list-attribute>
</definition>
general.jsp general.jsp
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<tiles:importAttribute name="styles"/>
<tiles:importAttribute name="scripts"/>
<tiles:importAttribute name="page_scripts" ignore="true"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<c:forEach var="css" items="${styles}">
<link rel="stylesheet" type="text/css" href="<c:url value="${css}"/>" media="screen,projection">
</c:forEach>
<c:forEach var="script" items="${scripts}">
<script src="<c:url value="${script}"/>"></script>
</c:forEach>
<c:forEach var="script" items="${page_scripts}">
<script src="<c:url value="${script}"/>"></script>
</c:forEach>
</head>
<body>
<div id="main">
<div class="wrapper">
<section id="content">
<tiles:insertAttribute name="body" />
</section>
</div>
</div>
</body>
tile.xml tile.xml
<tiles-definitions>
<definition name="solution/list" extends="template.general">
<put-attribute name="body" value="/WEB-INF/view/solution/list.jsp" />
<put-list-attribute name="page_scripts">
<add-attribute value="/media/js/plugins/jquery.dataTables.js" />
</put-list-attribute>
</definition>
</tiles-definitions>
list.jsp list.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<table id="solutionList" class="responsive-table display" cellspacing="0">
<thead>
<tr>
<th>Name</th>
<th>Descripción</th>
</tr>
</thead>
<tbody>
<c:forEach var="solution" items="${solutions}">
<tr>
<td>${solution.solutionName}</td>
<td>${solution.description}</td>
</tr>
</c:forEach>
</tbody>
</table>
<script>
$('solutionList').dataTable({
responsive : true
});
</script>
why when I run this application the script in list.jsp doesn't load? 为什么当我运行此应用程序时,list.jsp中的脚本未加载? also, chrome devtools marks the line with 'failed to load resource: the server responded with a status of 404'.
同样,chrome devtools将行标记为“无法加载资源:服务器以404状态响应”。
I think and see you didn't select the table 我认为,您没有选择表格
you don't have #
in $('solutionList').dataTable({ responsive : true });
您在
$('solutionList').dataTable({ responsive : true });
没有#
$('solutionList').dataTable({ responsive : true });
so correct to $('#solutionList').dataTable({ responsive : true });
因此更正为
$('#solutionList').dataTable({ responsive : true });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.