2013-10-17 86 views
0

朋友, 我想將文本字段值傳遞到下一個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作爲輸出。

+0

顯示窗體標籤。或者你是否在表單標籤中給出了第二個jsp頁面的操作? – Subin

+0

你的問題解決了嗎? –

回答

0

我沒有在您的代碼中看到<表單>元素。您應該用<表格>包圍您的表格,並將您的操作更改爲POST。

+0

在窗體中有

+0

將您的表單操作更改爲POST。我也注意到你的提交中有onclick = move()。請刪除它。 – AValchev

0

在您所使用的形式name屬性兩次,這就是爲什麼你在second.jsp

<input type=text name=lab name="sysId" value="Sys. Id" size=10> 
       ↑  ↑ 

越來越null使用一個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

有用的鏈接