Carlos Schuldiner Carlos Schuldiner - 5 months ago 35
Java Question

Script tag not working

I am creating an application using spring and tiles. I have a general template where all the js and css are loaded. 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

<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

<%@ 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

<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

<%@ 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? also, chrome devtools marks the line with 'failed to load resource: the server responded with a status of 404'.

Answer

I think and see you didn't select the table

you don't have # in $('solutionList').dataTable({ responsive : true });

so correct to $('#solutionList').dataTable({ responsive : true });

Comments