Kuldeep Kashyap
Kuldeep Kashyap

Reputation: 33

I am using hidden input type to set value and using request.getParameter() to get the value in another page but it is always returning “null”

I am using hidden input type to set value and using request.getParameter() to get the value in another page but it is always returning “null”. Why it is returning null value? First Page:-

<%  
try{  
       Class.forName("org.postgresql.Driver");  
       Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/passkey_database","postgres","4457");  
       PreparedStatement ps=con.prepareStatement("select * from visitor_table");  
       ResultSet rs=ps.executeQuery();  
       ResultSetMetaData metaData=rs.getMetaData();  
       while(rs.next()){  

%>  
<tr>
 <td>  
  <input type="text" name="name" value="<%=rs.getString("visitor_name")%>">  
  <a href="permissionform.jsp"> <%=rs.getString("visitor_name")%> </a>  
</td>
<%for(int i = 2; i<=metaData.getColumnCount();i++){ %>  
<td>  
  <%= rs.getString(i)%>  
</td>
<%    }   %>     
</tr>
<%}  
}catch (Exception e) {  
e.printStackTrace();  
}

Second Page:-

 <%

   String name=request.getParameter("name");
    out.println(name);
   try{
       Class.forName("org.postgresql.Driver");
        Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/passkey_database","postgres","4457");
            PreparedStatement ps=con.prepareStatement("select * from visitor_table where visitor_name=?");
            ps.setString(1,name);
            ResultSet rs=ps.executeQuery();
            while(rs.next()){

  %>

Upvotes: 0

Views: 1215

Answers (2)

Chirag
Chirag

Reputation: 565

You can do this task by just a simple trick

update this line

<%
        String visitor_name = rs.getString("visitor_name");
        String link = "permissionform.jsp?name=" + visitor_name;
    %>
    <input type="text" name="name" value="<%=visitor_name%>">  
    <a href="<%=link%>"><%= visitor_name%></a>  

by this code you really dont need the <input> tag if you use this code because link is already parsed.

by this name value forworded will not be null if visitor_name is not null

Hope it helps your problem.:)

Upvotes: 2

Seymur Asadov
Seymur Asadov

Reputation: 672

You can use Session , Cookie or Context objects to get variable in other page,or use form tag with action another page if you have <input type="submit"/> tag

try this code

 <td> 
     <form action="permissionForm.jsp"> 
      <input type="text" name="name" 
       value="<%=rs.getString("visitor_name")%>">  
     <input type="submit" value="<%=rs.getString("visitor_name")%>"/>
    </form>    
</td>

Upvotes: 0

Related Questions