我试图从表中选择一个特定字段并将值从一个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并将其传递给另一个名为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
答案 0 :(得分:1)
String id1 = request.getParameter("id");
您的原始代码会查找名为id
的局部变量,并且未定义此类变量。
也就是说,你不应该在JSP中使用scriptlet。使用JSP EL:
${param.id}