0

我正在尝试从表中选择特定字段并将值从一个 jsp 传递到另一个。我的第一个 jsp 文件如下

列表.jsp

<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
   <title>Insert title here</title>
 </head>
 <body>

   <form method="POST" action="/Spring/deletedpage.jsp">

   <table BORDER="1">
    <tr>
         <TH width="50">Id</TH>
         <TH width="150">First Name</TH>
         <TH width="150">Last Name</TH>
         <TH width="100">Money</TH>
         <TH width="50">Currency</TH>
     </tr>
     <c:forEach items="${userList}" var="person">
     <tr>
         <td><input type="checkbox" name ="id" value="${person.id}"> <c:out 
               value="${person.id}" /></td>
         <td><c:out value="${person.name}" /></td>
         <td><c:out value="${person.password}" /></td>
         <td><c:out value="${person.gender}" /></td>
         <td><c:out value="${person.country}" /></td>
       </tr>
      </c:forEach>
     </table>
     <input type="submit"> 
     </form>
         <input type="submit" value="edit"/> 

    </body>
   </html>

我从表中选择一个 id 并将其传递给另一个名为 deletedpage.jsp 的 jsp,如下所示

<html>
 <head>
   <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
   <title>Insert title here</title>
 </head>
 <body>

  <%
     String id1=request.getParameter(id);
      int id2=Integer.parseInt(id1);
      System.out.println(id1);
  %>
 <form method="POST" action="<%=request.getContextPath()%>/deletedpage/delete">

       <P>Are you sure you want to delete this user??</P>
       <input type="submit" value="Yes" />

   </form>
    <p> <a href="frm4.jsp">No</a></p>
  </body>
 </html>

但我在以下行中收到错误

 String id1=request.getParameter(id);

作为

id cannot be resolved
4

1 回答 1

1

你可能想要

String id1 = request.getParameter("id");

您的原始代码查找名为 的局部变量id,但未定义此类变量。

也就是说,您不应该在 JSP 中使用 scriptlet。使用 JSP EL:

${param.id}
于 2013-05-31T06:57:43.240 回答