Home > Enterprise >  Href isn't redirecting
Href isn't redirecting

Time:05-17

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

CodePudding user response:

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>
  • Related