2

I created the below frontend part for my Spring Boot Application. In this picture I've placed my cursor on the first News Link url and you can see at the bottom left corner that the link appears as it should be, just before I click it.

FrontEnd for Spring Boot App

When I click it, instead of

https://www.investing.com/news/cryptocurrency-news/ethereum-climbs-12-in-rally-2848020

I am being redirected to

https://www.investing.com/

From what I am thinking I have to firstly pass the URLs in my controller like this example and secondly to implement a redirection like this example. I tried the next method with no success. What am I doing wrong? I am new to Spring and I am struggling many days on this.

Failed Controller Attempt

    @RequestMapping("/${rate.news_link}")
    public String redirect() {
        return "redirect:/";
    }

Below my HTML Thymeleaf template,

HTML Thymeleaf

<!DOCTYPE HTML>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<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" target="_blank">Github</a></li>
</ul>

<main role="main" class="container">

    <div class="starter-template">
        <h1>Cryptocurrency News</h1>
    </div>

</main>
    <!--Display DB contents on HTML and Thymeleaf-->

    <div class="container text-center" id="tasksDiv">
        <hr>
        <div class="table-responsive">
            <table class="table table-striped table-bordered">
                <thead>
                <tr>
                    <th>News Provider Name</th>
                    <th>News Link</th>
                    <th>Related Image</th>
                </tr>
                </thead>
                <tbody>
                    <tr th:each="rate: ${rates}">
                        <td th:text="${rate.news_provider_name}"> </td>
                        <td>
                            <a

                                    href="#"
                                    th:href="@{${rate.news_link}}"
                                    th:text="${rate.HEADLINE}"/>
                        </td>
                        <td> <img th:src="${rate.related_image}" alt="error displaying image"> </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>


</body>
</html>
Vel_More
  • 293
  • 1
  • 10
  • This looks like it may be a duplicate of a question you already asked a few days ago: [Thymeleaf URL Forwarding Problem to External URL in Spring Boot App](https://stackoverflow.com/q/72940598/12567365). If it's _not_ a duplicate, you can link to the original question and clarify why it's not a dupe of that one. Otherwise, you can add any clarifications to the original question (as long as they don't significantly change the nature of the question). [How to ask same question again on Stack Overflow?](https://meta.stackoverflow.com/q/339624/12567365) – andrewJames Jul 16 '22 at 17:42
  • 1
    @andrewJames as I was searching and studying about the issue, I realised that my initial question wasn't sufficient enough to provide the necessary details. It is indeed for the same problem though. Since it's stricted to delete questions, I am thinking about how to transform my first question to a valuable one. Thank you for your clarification. – Vel_More Jul 16 '22 at 18:24

0 Answers0