朋友们,我想将文本字段值传递到下一个jsp页面。当我尝试这样做时,下一个jsp页面总是显示该变量的空值。请告诉我如何做这件事......
我的代码是
<form name="lab" action="second.jsp" method="get">
<table>
<tr>
<td style="margin-left:10px">Enter Lab</td>
<td><select name="labName">
<option>--select lab---</option>
<option>Lab-01</option>
<option>Lab-02</option>
<option>Lab-03</option>
<option>Lab-04</option>
<option>Lab-05</option>
<option>Lab-06</option>
<option>Lab-07</option>
<option>Lab-08</option>
<option>Lab-09</option>
<option>Lab-10</option>
</select></td>
</tr>
<tr>
<td width=100px>Enter Location</td>
<td> <select name="location">
<option>--select location--</option>
<%
for(i=1;i<=60;i++)
{
%><option><%out.print(i);%></option><%
}
%>
</select></td>
</tr>
<tr>
<td width=100px>Enter System ID </td>
<td><input type=text name=lab name="sysId" value="Sys. Id" size=10></td>
</tr>
<tr>
<td><hr><b</td>
<td><hr></td>
</tr>
<tr>
<td align=center class="cells" width=100px><input type="submit" name=submit value=ADD hight=10px width=20px onclick="move();"></td>
<td align=center class="cells" width=10px ><input type=button name=submit value=cancel>
</td>
</tr>
</table>
</form>和下一页second.jsp
<%
String id=request.getParameter("sysId");
out.print(id);
%>它给出null作为输出。
发布于 2013-10-17 14:10:10
我在你的代码中看不到元素。您应该在您的桌子周围使用,并将您的操作更改为POST。
发布于 2013-10-17 16:02:50
在表单中,您使用了两次name属性,这就是在second.jsp中获取null的原因
<input type=text name=lab name="sysId" value="Sys. Id" size=10>
↑ ↑ 使用一个name属性作为
<input type=text name="sysId" value="This is sysId" size=10> 然后在second.jsp中
String id=request.getParameter("sysId"); //make sure you type correct name here
out.print(id);它将打印:This is sysId
与无关的
我建议不要使用Scriptlets
<select name="location">
<option>--select location--</option>
<%
for(i=1;i<=60;i++)
{
%><option><%out.print(i);%></option><%
}
%>
</select>您可以将代码修改为
<select name="location">
<option>--select location--</option>
<c:forEach varStatus="i" begin="1" end="60">
<option>${i.count}</option>
</c:forEach>
</select> 这叫做JSTL,只要把jstl-1.2.jar放在/WEB-INF/lib里就行了
有用的链接
https://stackoverflow.com/questions/19419391
复制相似问题