将 JSP 中的参数传递给 Servlet

Passing Parameters in JSP to Servlet

我有以下代码

JSP

         <tbody>
            <c:forEach var="defect" items="${defects}">
                <tr>
                    <td>${defect.name}</td>
                    <td>${defect.description}</td>
                    <td>${defect.summary}</td>
                    <td>${defect.priority}</td>
                    <td>${defect.originator.name}</td>
                    <td>${defect.assignee.name}</td>
                    <td>
                        <form action="AllOpenDefects?defectId=${defect.id}" method="get">
                            <input type="submit" value="Update" />
                        </form> 
                    </td>
                </tr>
            </c:forEach>
        </tbody>

Servlet(在 doGet 方法中)

System.out.println((String) request.getParameter("defectId")); // It is printing null

并且在 url 中 defectIdNOT 被追加......我的代码有什么问题吗?

编辑: url 是 http://localhost:8080/BugManagemetSystem/AllOpenDefects 但它应该像 http://localhost:8080/BugManagemetSystem/AllOpenDefects?defectId=2

恕我直言,您问题的简短答案是 "your code is ok"。

附带说明一下,如果它没有产生新的要求 link,通常是更新问题。例如。尝试更改 URL algtogether 只是为了测试(表单 action="Junk"),看看浏览器是否捕捉到它。 如果没有,请尝试清除各种缓存 - 浏览器缓存,删除展开的 war 和工作目录(例如,在 Tomcat 中是 /webapps/myapp/ 和 /work)...

您的浏览器似乎清除了 action="..." 属性中 ?... 之后的参数。在那种情况下,尝试通过 <input type="hidden" .../> 传递它,例如

<form action="AllOpenDefects" method="get">
    <input type="hidden" name="defectId" value="${defect.id}"/>
    <input type="submit" value="Update" />
</form> 

这种方式应该将它们添加到 URL 作为 ?defectId=value of ${defect.id}.