Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
deepstar@gmail.com - 16 Nov 2005 15:32 GMT
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)

       {
}   %>
deepstar@gmail.com - 16 Nov 2005 16:17 GMT
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)

       {
}   %>
Andrew Thompson - 16 Nov 2005 16:26 GMT
> ..Any pointers at all?

- Wait 48 hours before considering getting impatient.
- Read the group while waiting.
deepstar@gmail.com - 16 Nov 2005 16:17 GMT
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)

       {
}   %>


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.