• Post Reply Bookmark Topic Watch Topic
  • New Topic

Selecting displayed query results using JSP

 
Donald Nunn
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, fellow ranchers. Would anyone happen to know how to select rows using JSP that's a result of a database query and once the desired row is selected, pass the parms associated with that row to another jsp that will query the database and display the results.
Id Name Address
---- ------- ------------
10 Bill 123 cedar rd.
20 Bob 456 elm street
select the desired row and pass the ID as parameter to another jsp that will display the results of the query.
Thanks,
Donald

[ February 01, 2002: Message edited by: Donald Nunn ]
[ February 01, 2002: Message edited by: Donald Nunn ]
 
Gabriel Fox
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Donald, if i got your question right this should be a possible solution:
1. After running the query on JSPA ,U 'll want
to store the resultset somewhere,say
an object that mimicks(ResultSetMetadata) or CachedRowSet.OR: if U are coupling Ur Database operations to your JSP by using this:
while(resultSetRef.next())
{
//Looping thru your resultset
}
2.Then as U loop thru your resultset,for each record get the unique ID for each row as U display the data U are interested in.then,store the ID in a variable,say :
String varID=resultSetRef.getInt("Id")
3.For each row ,U want to display a link
using say :
<A href="FormHandlerName"?fieldName=varID> Select </A>
4. After this page is submitted to FormHandlerName, fieldName goes with the request and U can get on your destination page(request.getParameter("fieldName")) after using say Ur forward() method in FormHandlerName.
Note:
a. Links are handled by doGet() method
in servlets if that is Ur formhandler/controller
b.U can call a doGet() from a doPost() and vice-versa
3.There are many ways around this problem depending on Ur design .
 
Hari Haran
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Donald,
If I understand ur Question right this is what u want.
Eg:
U display the ID Name and Address which is a result of a Query.
Now when u click on the Id ,probably u want that id's some other details(say if it is a custome, u want his balance details).Right...
If this was ur question then u can pass the ID appended with the Query string.
Proceed in the following way..
Run a loop through the result set
Display the id as follows
<tr>
<td><a href="Balance.jsp?Id = <%out.println(str_Id);%>"> <%out.println(str_Id);%>
</href>
</td>
<td><%out.println(str_Name);%></td>
<td><%out.println(str_Address);%></td>
</tr>
</tr>
Now when u click on the ID the corresponding jsp,page will be called.
There u can call your beans get method using this id as a parameter.
Hope it helps...
:roll:
[ February 05, 2002: Message edited by: Hari Haran ]
 
Joe Pardi
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out http://www.dotjonline.com/taglib/grid.jsp
 
Donald Nunn
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello and thanks guys for your great responses. I did get it to work and I used a combination of all of the great suggestions.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!