0

Friends, I want to pass text field value to next jsp page . When i am trying to do this next jsp page always show null value for that variable. please tell me how can i do this.......

my code is

   <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>

and next page second.jsp

 <%
                String id=request.getParameter("sysId");
                out.print(id);
  %>

It give null as output.

2 Answers2

0

I don't see <form> element in your code. You should surround your table with <form> and change your action to POST.

Valchev
  • 1,490
  • 14
  • 17
0

In the form you have used name attribute twice that why you are getting null in second.jsp

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

Use one name attribute as

<input type=text name="sysId" value="This is sysId" size=10>  

Then in second.jsp

String id=request.getParameter("sysId");  //make sure you type correct name here
out.print(id);

It will print : This is sysId


Not related

I recommend not to use Scriptlets

<select name="location">
    <option>--select location--</option>
<%  
    for(i=1;i<=60;i++)
    {
        %><option><%out.print(i);%></option><%
    }
%>
    </select>

You can modify the code as

<select name="location">
    <option>--select location--</option>
    <c:forEach varStatus="i" begin="1" end="60">
    <option>${i.count}</option>
    </c:forEach>
</select>  

It is called JSTL just put jstl-1.2.jar in /WEB-INF/lib

Useful link

Community
  • 1
  • 1
Aniket Kulkarni
  • 12,825
  • 9
  • 67
  • 90