0

I have this code in JSP:

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%--   Created by IntelliJ IDEA.   User: PC   Date: 02.05.2022   Time: 15:20   To change this template use File | Settings | File Templates.
--%> <%@ page contentType="text/html;charset=UTF-8" language="java" %>


<html> <head>
    <title>Title</title> </head> <body> <h1>Dashboard</h1> <br>


<table>
    <tr>
        <th>Banners</th>
        <th>Localization</th>
    </tr>
    <%--@elvariable id="banners" type="java.util.List<pl.coderslab.entity.Banners>"--%>
    <c:forEach var="banner" items="${banners}">

        <tr>
            <td>Banner</td>
            <td>${banner.street}</td>
            <td> <a href="localhost:8080/dashboard/info/${banner.id}" >Wiecej informacji </a></td>
            <td> <a href="localhost:8080/dashboard/edit/${banner.id}" >Edytuj </a></td>
            <td> <a href="localhost:8080/dashboard/delete/${banner.id}" >Usun </a></td>
        </tr>
    </c:forEach>


</table>

</body> </html>

and also have controller:

@RequestMapping(value = "/dashboard/info/{id}", method = RequestMethod.GET)
    public String showInfo(Model model, @PathVariable("id") int id){
        List<Banners> banners = bannerDao.getBannerById(id);
        model.addAttribute("banner", banners);
        return "showInfo";

    }
    @RequestMapping(value = "/dashboard/info/{id}", method = RequestMethod.POST)
    public String info(){
        return "showInfo";
    }

The problem is that these href's aren't redirecting. When i click on them nothing happens, as if they were simple buttons. I don't have an idea, what to do here? 1st edit: Okay so answer from Halil Ibrahim Binol worked but now it shows me 404 error, even if I have @RequestMapping to this address

adihno
  • 3
  • 2

1 Answers1

0

Did you try adding http prefix?

<a href="http://localhost:8080/dashboard/info/${banner.id}" >Wiecej informacji</a>

Or you can use;

<a href="//localhost:8080/dashboard/info/${banner.id}">Wiecej informacji</a>

This will be use current page protocol. When you are in https page it will convert to https://localhost:8080/...

Edit:

Alternatively, when your code is running in same server. You can use;

<a href="/dashboard/info/${banner.id}">Wiecej informacji</a>
  • Actually it worked but now there is another question. When it redirects I have 404 error, even if I have controller and RequestMapping for this adress – adihno May 16 '22 at 13:05
  • I don't know your resource file structure. Are you using thymeleaf? May this question will help https://stackoverflow.com/q/60002080/7335176 – halil ibrahim binol May 16 '22 at 13:20
  • Unfortunatelly im using JSP but have added properties to application.properties : spring.mvc.view.prefix=WEB-INF/jsp/ spring.mvc.view.suffix=.jsp So it should recognize it as rest of my views – adihno May 16 '22 at 13:24
  • And trail to jsp files is same as in these properties: webapp/WEB-INF/jsp – adihno May 16 '22 at 13:27
  • I think it's a completely different question. You may want to open another question. Of course you must search for same issue! BTW you can accept my answer if my answer is solve your problem. – halil ibrahim binol May 16 '22 at 13:30
  • Ok, thanks for help, I will open another question :D – adihno May 16 '22 at 13:32