我在 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>
并且還有控制器:
@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";
}
問題是這些href 沒有重定向。當我點擊它們時,沒有任何反應,就好像它們是簡單的按鈕一樣。我不知道,在這里做什么?第一次編輯:好的,所以 Halil Ibrahim Binol 的回答有效,但現在它顯示了 404 錯誤,即使我有 @RequestMapping 到這個地址
uj5u.com熱心網友回復:
您是否嘗試添加http前綴?
<a href="http://localhost:8080/dashboard/info/${banner.id}" >Wiecej informacji</a>
或者你可以使用;
<a href="//localhost:8080/dashboard/info/${banner.id}">Wiecej informacji</a>
這將使用當前頁面協議。當您在https頁面中時,它將轉換為 https://localhost:8080/...
編輯:
或者,當您的代碼在同一臺服務器上運行時。您可以使用;
<a href="/dashboard/info/${banner.id}">Wiecej informacji</a>
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/475980.html
