getParameterValues() not formatting correctly


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: getParameterValues() not formatting correctly

  1. #1
    Join Date
    Feb 2005
    Posts
    1

    getParameterValues() not formatting correctly

    Hi,
    I am using getParameterValues() in my servlet to retrieve a hidden field from my jsp. The hidden field contains the results of a listbox so multiple values for one var. My problem is that the servlet reads it in as one long string "selected=Test1&selected=Test2&". I thought I had the formatting correct but it doesn't seem to be working can someone take a look at my code and see where I am going wrong? Thanks!


    String[] Language = request.getParameterValues("hidden1");
    try {



    statement.executeUpdate("Delete * from partdb.profile_lang where partid = \"" + PartID + "\" ");

    for(int j=0; j<Language.length; j++)
    {
    statement.executeUpdate("Insert into partdb.profile_lang (language, partid) "
    + " values(\"" + Language[j] + "\", \"" + PartID + "\") ");

  2. #2
    Join Date
    Feb 2005
    Posts
    5

    Smile getParameterValues() not formatting correctly

    Hi Magoo,

    When you put the values in the hidden field in the Jsp as one string, only put the values don'r put selected in the string.

    In the your servlet user getParameter for the hidden field and take it into a temporary string.

    After that usibf the String Tokenizer on "&" create a array of string or you can directly loop through StringTokenizer to generate the Query.


    Something like this


    Assumming you have the hidden field contains the results of a listbox ( multiple values) into one long string as "Test1&Test2&Test3".


    Now in you servlet use the following code

    String language = request.getParameter("hidden1");
    StringTokenizer strToken = null;



    statement.executeUpdate("Delete * from partdb.profile_lang where partid = \"" + PartID + "\" ");

    strToken = new StringTokenizer (language,"&");
    while( strToken.hasMoreElements())
    {
    statement.executeUpdate("Insert into partdb.profile_lang (language, partid) "
    + " values(\"" + (String)strToken.nextToken() + "\", \"" + PartID + "\") ");

    }



    -Zeon
    Be a Creator .... not a creature of your circumstances !!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center