• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Display a list based on JSP input

 
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you enter a text string in an HTML TEXT control and you then want to go to another JSP page and dymamically create/populate some values in a "list" of some kind, ***based on what the user entered on the last JSP page***, is this HTML, DHTML, or something else?
I'm not asking about "how" to get the data. Assume that in the second JSP page, I already have the data, but need to populate some kind of "picker" control, on the fly, that the user can use to choose the fields (values) he wants.
I'm not sure how to create a list on the fly.
I am using a bean to return the database results, and that part works fine.
I appreciate anyone's input on this.
Thanks.
-- Mike
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assumption:
First page selects cola manufacturer
Second page lists beverages made by the selected manufacturer.

You've already got the dynamic list of drinks, right? You told us to assume you had the data already.

If you already have the beverage list, then loop over the data, outputting checkboxes of the same name, but with different values (for example, the primary key of each drink). Another control you could use is the select control with multiple="multiple" attribute set. The loop would then be producing multiple option tags with different values.

Once this is submitted, it would be an array with the name of the checkboxes (or the select control), and would contain the primary key of only those drinks picked by the user from the list provided.

last little bit: If you 'already have the data', but that data is not already 'filtered' based on what the user had previously selected... so in my example, the user selects "pepsico international", but the list of drinks on the next page contains drinks by coca-cola, then I'd suggest re-writing your SQL query. Your query should return results based on the first selection.
[ July 25, 2002: Message edited by: Mike Curwen ]
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry I haven't been more clear.
Yes, the SQL works fine and correctly as you indicated it should. I wasn't focusing on the SQL.
My issue is how do you populate a HTML list at runtime? Is this just a JSP loop where you populate some HTML control?
Thanks.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps Something like this:
sample.jsp----
<html><head><title>foo</title></head>
<body>
<%@ page import="java.sql.*" %>
<table>
<tr>
<th>cata 1</th>
<th>cata 2</th>
</tr>
<%
Connection conn = null;
ResultSet rs = null;
Statement st = null;
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost/myDB");
st =conn.createStatement();
rs = st.executeQuery("select * from myTable");
while(rs.next()) {
%>
<tr><td>
<%= rs.getString("myElement") %></td>
<td>
<%= rs.getString("myOtherElement") %>
</td></tr>
<%
}
%>
</table>
<%
catch (Exception myEx) {
myEx.printStackTrace();
%>
</table>
Error
<%
} finally {
if (rs != null) rs.close();
if (st != null) st.close();
if (conn != null) conn.close();
}
%>
</body></html>
 
Ranch Hand
Posts: 3244
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mike
sounds like you're looking for a select list, in html the form it tales is:

IF you want the client to be able to select mopre than one option at a time then use the multiple option in the tag:
<select name="name" multiple>
When the user selects options and submits the form they'll come to the JSP or servlet as parameters of the HttpRequest.
so to dynamically create one, just get your data, create the initial tag, then loop through your data and generate the option tags, then close the switch tag.
hope that helps
 
Just the other day, I was thinking ... about this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic