retrieving options from a listbox, will need a masterprogrammer to solve!

D

deepstar

Hi masterprogrammers

I have a problem with my code, I can print out the text from my
textbox, but I can't print out the chosen option in my option box which
is generated from my Sql data (this is all on a single jsp page). I
have marked the line that tries to output the chosen listvalue but
which fails with //Doesn't work
Been trying for ages now, can anyone give me some hints?? thx

String chosenItem=request.getParameter("listedItem");
String[] getOptionValue = request.getParameterValues("listedItem");
String addedTagValue = null;

session.setAttribute("addedTags", addedTags);
session.setAttribute("listedItem", chosenItem);

%>
<H3>Items:</H3>
<SELECT SIZE="1" NAME="listedItem"> //The droplist

<%

//Read item names, generate droplist
ResultSet rslt = addStmt.executeQuery("SELECT name FROM
personal_item");
ResultSetMetaData rsmd = rslt.getMetaData();

for (int i = 1; i <= rsmd.getColumnCount(); i++) {

while(rslt.next()) {
String getItemName = rslt.getString(i);
getItemName = rslt.getString("name");
out.println("<option value='"+getItemName+"'>"
+getItemName+ "</option>");

}
}
rslt.close();
addStmt.close();
connection.close();%>

</SELECT>
<FORM METHOD="POST" ACTION="update.jsp?add=yes">
<BR/><BR/>
<H3>Tags:</H3>
<INPUT TYPE="text" NAME="addedTags" value=""><BR/><BR/>
<INPUT TYPE="submit" VALUE="submit">
<BR/>
</FORM>
<BR/>


<BR/>

<%
//Set Item tag
try {
if(request.getParameter("add").equals("yes")) {


out.println(addedTags);
//Works
for (int j = 0; j < getOptionValue.length; j++) {

out.println(getOptionValue[j]);
//Doesn't work


}
addStmt.close();
connection.close();
}
} catch (NullPointerException e)

{
} %>
 
D

deepstar

Okay, got it to print out the listbox value, but in this format:
"[Ljava.lang.String;@53a9d5 dummy" where dummy is the listbox item. Any
pointers at all? thx

<%
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
java.sql.Connection
connection=java.sql.DriverManager.getConnection("jdbc:mysql://localhost/tn20","root","arketype");
Statement addStmt = connection.createStatement();
Timestamp stamp = new Timestamp(System.currentTimeMillis());
java.util.Date date = new java.util.Date();

String chosenItem=request.getParameter("listedItem");
String[] getOptionValue = request.getParameterValues("listedItem");
String addedTagValue = null;

if(addedTags==null) addedTags="";
if(chosenItem==null) chosenItem="";

session.setAttribute("addedTags", addedTags);
//session.setAttribute("listedItem", chosenItem);

%>
<H3>Items:</H3>
<FORM METHOD="POST" ACTION="update.jsp?add=yes">
<SELECT SIZE="1" NAME="listedItem"> //The droplist

<%

//Read item names, generate droplist
ResultSet rslt = addStmt.executeQuery("SELECT name FROM
personal_item");
ResultSetMetaData rsmd = rslt.getMetaData();

for (int i = 1; i <= rsmd.getColumnCount(); i++) {

while(rslt.next()) {
String getItemName = rslt.getString(i);
getItemName = rslt.getString("name");
out.println("<option value='"+getItemName+"'>"
+getItemName+ "</option>");

}
}
rslt.close();
addStmt.close();
connection.close();%>

</SELECT>

<BR/><BR/>
<H3>Tags:</H3>
<INPUT TYPE="text" NAME="addedTags" value=""><BR/><BR/>
<INPUT TYPE="submit" VALUE="submit">
<BR/>
</FORM>
<BR/>


<BR/>

<%
//Set Item tag
try {
if(request.getParameter("add").equals("yes")) { //If button is
pressed

out.println(addedTags); //works
out.println(request.getParameterValues("listedItem"));
//works

for (int j = 0; j < getOptionValue.length; j++) {

out.println(getOptionValue[j]); //doesn't work

}
addStmt.close();
connection.close();
}
} catch (NullPointerException e)

{
} %>
 
D

deepstar

Okay, got it to print out the listbox value, but in this format:
"[Ljava.lang.String;@53a9d5 dummy" where dummy is the listbox item. Any
pointers at all? thx

<%

String chosenItem=request.getParameter("listedItem");
String[] getOptionValue = request.getParameterValues("listedItem");
String addedTagValue = null;

if(addedTags==null) addedTags="";
if(chosenItem==null) chosenItem="";

session.setAttribute("addedTags", addedTags);
//session.setAttribute("listedItem", chosenItem);

%>
<H3>Items:</H3>
<FORM METHOD="POST" ACTION="update.jsp?add=yes">
<SELECT SIZE="1" NAME="listedItem"> //The droplist

<%

//Read item names, generate droplist
ResultSet rslt = addStmt.executeQuery("SELECT name FROM
personal_item");
ResultSetMetaData rsmd = rslt.getMetaData();

for (int i = 1; i <= rsmd.getColumnCount(); i++) {

while(rslt.next()) {
String getItemName = rslt.getString(i);
getItemName = rslt.getString("name");
out.println("<option value='"+getItemName+"'>"
+getItemName+ "</option>");

}
}
rslt.close();
addStmt.close();
connection.close();%>

</SELECT>

<BR/><BR/>
<H3>Tags:</H3>
<INPUT TYPE="text" NAME="addedTags" value=""><BR/><BR/>
<INPUT TYPE="submit" VALUE="submit">
<BR/>
</FORM>
<BR/>


<BR/>

<%
//Set Item tag
try {
if(request.getParameter("add").equals("yes")) { //If button is
pressed

out.println(addedTags); //works
out.println(request.getParameterValues("listedItem"));
//works

for (int j = 0; j < getOptionValue.length; j++) {

out.println(getOptionValue[j]); //doesn't work

}
addStmt.close();
connection.close();
}
} catch (NullPointerException e)

{
} %>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,132
Latest member
TeresaWcq1
Top