2013-05-31 44 views
0

我試圖從表中選擇一個特定的領域,從一個JSP傳遞值another.My第一個JSP文件如下想知道如果我的JSP格式正確

的List.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並將它傳遞給另一個JSP命名deletedpage.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 
+0

你應該在引號之間加上id,例如String id1 = request.getParameter(「id」);此外爲什麼scriplets – mprabhat

回答

1

你可能想

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

你原來的代碼查找名爲id一個局部變量,而不是限定的這樣的變量。

也就是說,你不應該在JSP中有腳本。使用JSP EL:

${param.id} 
+0

使用jsp el還可以節省大約4行:) – youri

+0

我是一個這樣的白癡...... thnx爲你的幫助 – Ezhil