HTML page redirection problem with Thymeleaf in Spring Boot App
تبليغيرجى شرح بإيجاز لمإذا تشعر أنك ينبغي الإبلاغ عن هذا السؤال.
I’ve created a Spring Boot App, in which I am fetching data from external API, store them in database and then displaying them back at front-end in HTML using Thymeleaf. Everything works perfectly fine except one thing.
One of the columns in db, has the name “Headline” which is mapped as String variable. I am using this variable as hyperlink in my Spring Boot app combined with stored URLs stored in the same database, to redirect to the source of them. Below I am showing my front-end code.
Front-End Page
<!DOCTYPE HTML>
<html lang=”en” xmlns:th=”http://www.thymeleaf.org” xmlns:c=”http://www.w3.org/1999/XSL/Transform”>
<head>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1, shrink-to-fit=no”>
<title>Spring Boot Thymeleaf Hello World Example</title>
<link rel=”stylesheet” th:href=”@{/webjars/bootstrap/css/bootstrap.min.css}”/>
<link rel=”stylesheet” th:href=”@{/styles/db.css}”/>
<script type=”text/javascript” th:src=”@{/webjars/bootstrap/js/bootstrap.min.js}”></script>
</head>
<body>
<ul>
<li><a href=”http://localhost:8080/”>Home</a></li>
<li><a href=”https://github.com/Andreas-Kreouzos”>Github</a></li>
</ul>
<main role=”main” class=”container”>
<div class=”starter-template”>
<h1>IoT Application</h1>
</div>
</main>
<!–Display DB contents on HTML and Thymeleaf–>
<div class=”container text-center” id=”tasksDiv”>
<h3>Database Contents</h3>
<hr>
<div class=”table-responsive”>
<table class=”table table-striped table-bordered”>
<thead>
<tr>
<th>news_id</th>
<th>news_provider_name</th>
<th>HEADLINE</th>
<th>news_link</th>
<th>related_image</th>
<th>Timestamp</th>
</tr>
</thead>
<tbody>
<tr th:each=”rate: ${rates}”>
<td th:text=”${rate.news_id}”> </td>
<td th:text=”${rate.news_provider_name}”> </td>
<td th:text=”${rate.HEADLINE}”> </td>
<td> <a th:href=”${rate.news_link}”> <p th:text=”${rate.HEADLINE}”> </a> </td>
<td> <img th:src=”${rate.related_image}” alt=”error displaying image”> </td>
<td th:text=”${rate.timestamp}”> </td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>
When I am running my application everything displays just fine, but as soon as I press the texted hyperlinks, I am redirected at the home page instead of the given URLs, I’ve stored in my DB. Below, I am showing you my printscreen in which you can definitely see that URLs have been fetched and assigned properly, when I am hovering my cursor above them in my browser. But if press that hyperlink I am getting redirection here, instead of
here.
Any ideas about what am I doing wrong?
أضف إجابة