英文:
Spring Boot: Accessing Thymeleaf Model Attributes in Javascript getting the Error
问题
Getting this Error...while using inline JavaScript in Thymeleaf.
This Error is showing in my console..
com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:166) ~[jackson-databind-2.10.2.jar:2.10.2]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:145) ~[jackson-databind-2.10.2.jar:2.10.2]
2020-04-06 12:47:31.262 ERROR 6764 --- [nio-8080-exec-2] s.e.ErrorMvcAutoConfiguration$StaticView : Cannot render error page for request [/filter] and exception [An error happened during template parsing (template: "class path resource [templates/employeesFiltered.html]")] as the response has already been committed. As a result, the response may have the wrong status code.
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="layouts :: header"></head>
<body>
<nav th:replace="layouts :: navbar"></nav>
<div class="container">
<h3>Employee Directory</h3>
<hr>
<!-- Add New Employees Button -->
<a th:href="@{/employees/new}" class="btn btn-primary btn-sm mb-3">
Add Employee </a> <input id="txt-search" type="text" class="form-control"
name="keyword" placeholder="Search...">
<table class="table table-bordered table-striped">
<thead class="thead-dark">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr th:each="aEmployee : ${employees}">
<td th:text="${aEmployee.firstName}" />
<td th:text="${aEmployee.lastName}" />
<td th:text="${aEmployee.email}" />
</tr>
</tbody>
</table>
</div>
<!-- According to the official documentation: -->
<script th:inline="javascript">
/*<![CDATA[*/
var user = /*[[${employees}]]*/;
alert(user);
/*]]>*/
</script>
</body>
</html>
英文:
Getting this Error...while using inline JavaScript in Thymeleaf.
This Error is showing in my console..
com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:166) ~[jackson-databind-2.10.2.jar:2.10.2]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:145) ~[jackson-databind-2.10.2.jar:2.10.2]
2020-04-06 12:47:31.262 ERROR 6764 --- [nio-8080-exec-2] s.e.ErrorMvcAutoConfiguration$StaticView : Cannot render error page for request [/filter] and exception [An error happened during template parsing (template: "class path resource [templates/employeesFiltered.html]")] as the response has already been committed. As a result, the response may have the wrong status code.
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="layouts :: header"></head>
<body>
<nav th:replace="layouts :: navbar"></nav>
<div class="container">
<h3>Employee Directory</h3>
<hr>
<!-- Add New Employees Button -->
<a th:href="@{/employees/new}" class="btn btn-primary btn-sm mb-3">
Add Employee </a> <input id="txt-search" type="text" class="form-control"
name="keyword" placeholder="Search...">
<table class="table table-bordered table-striped">
<thead class="thead-dark">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr th:each="aEmployee : ${employees}">
<td th:text="${aEmployee.firstName}" />
<td th:text="${aEmployee.lastName}" />
<td th:text="${aEmployee.email}" />
</tr>
</tbody>
</table>
</div>
<!-- According to the official documentation: -->
<script th:inline="javascript">
/*<![CDATA[*/
var user = /*[[${employees}]]*/;
alert(user);
/*]]>*/
</script>
</body>
</html>
专注分享java语言的经验与见解,让所有开发者获益!
评论