<c:param> 值属性无法正常工作

<c:param> value attribute not working properly

在我的 Java spring mvc web 应用程序中,我想在 link 中传递一个请求参数。以下是 .jsp 页面代码的一部分 `

           <c:url var = "updateLink" value="/customer/showFormForUpdate">
           <c:param name="customerId" value="${tempCustomer.id}"></c:param>
           </c:url>

           <c:forEach var="tempCustomer" items="${customers}">

             <tr>
                <td> ${tempCustomer.firstName} </td>
                <td> ${tempCustomer.lastName} </td> 
                <td> ${tempCustomer.email} </td>
                <td> ${tempCustomer.id} </td>



                <td>    <a href="${updateLink}">Update</a> </td>

下面的代码部分工作得很好..它显示 'tempCustomer' 的客户 ID。

<td> ${tempCustomer.id} </td>

然而,

<c:url var = "updateLink" value="/customer/showFormForUpdate">
       <c:param name="customerId" value="${tempCustomer.id}"></c:param>

这部分代码不能正常工作。 value="${tempCustomer.id}" 根本不传递 tempCustomer.id 的值。当我点击时,更新 link

   <td>    <a href="${updateLink}">Update</a> </td>

url 看起来像这样

http://localhost:8080/web-customer-tracker/customer/showFormForUpdate?customerId=

参数值不存在。 url 应该包含 customerId 参数的值。

为了完整参考,这里是完整的 .jsp 页面代码

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<title>List Customers</title>




<link type="text/css" rel="stylesheet"
 href="${pageContext.request.contextPath}/resources/css/style.css"/>


</head>
<body>

        <div id ="wrapper">
            <div id ="header">
                <h2>CRM - Customer Relationship Manager</h2>
            </div>
        </div>

        <div id ="container">

            <div id = "content">

            <input type="button" value="Add Customer"
            onclick="window.location.href='showFormForAdd';return false;"
            class="add-button"          />


            <table>
               <tr>
                    <th>First Name</th>
                    <th>Last Name</th>
                    <th>Email</th>
              </tr>

               <!-- ${tempCustomer.id}
                -->
               <c:url var = "updateLink" value="/customer/showFormForUpdate">
               <c:param name="customerId" value="${tempCustomer.id}"></c:param>
               </c:url>

               <c:forEach var="tempCustomer" items="${customers}">

                 <tr>
                    <td> ${tempCustomer.firstName} </td>
                    <td> ${tempCustomer.lastName} </td> 
                    <td> ${tempCustomer.email} </td>
                    <td> ${tempCustomer.id} </td>



                    <td>    <a href="${updateLink}">Update</a> </td>


               </c:forEach>

            </table>


            </div>

        </div>

</body>
</html>
       <c:url var = "updateLink" value="/customer/showFormForUpdate">
           <c:param name="customerId" value="${tempCustomer.id}"></c:param>
       </c:url>

       <c:forEach var="tempCustomer" items="${customers}">

         <tr>
            <td> ${tempCustomer.firstName} </td>
            <td> ${tempCustomer.lastName} </td> 
            <td> ${tempCustomer.email} </td>
            <td> ${tempCustomer.id} </td>

您在 c:forEach 中定义了 tempCustomer 变量。它只存在于c:forEach的范围内。将 c:url 块移动到 c:forEach.