Message UK <[EMAIL PROTECTED]> wrote:

>Hi there.. I have a problem with getting parameters in a servlet -
>specifically the order in which my parameters are submitted.
[...]
>Does anyone know how to control the order in which parameters are
submitted,
>or any other help as to what I'm not doing??

The parameters can come in any order. One way of dealing with it is to
retrieve your parameters in alphabetical order and make sure to alphabetize
your fields in your HTML form. An easy way to alphabetize them is to prepend
a number to each one: 01_name, 02_age, 03_pumpkin, etc.

Here's some sample code to do the alphabetization (I haven't tried compiling
this...):

  import com.objectspace.jgl.*;
  import com.objectspace.jgl.predicates.*;
  import java.util.*;

  // ...

  String        name  = null;
  Enumeration   names = null;
  PriorityQueue queue = null;
  String        value = null;

  names = request.getParameterNames();
  queue = new PriorityQueue( new GreaterEqualString() );

  while ( names.hasMoreElements() )
  {
    name = (String)names.nextElement();

    if ( ( name != null ) && ( name.length() > 0 ) )
    {
      queue.push( name );
    }
  }

  while ( ! queue.isEmpty() )
  {
    name = (String)queue.pop();
    value = request.getParameter( name );

    if ( value != null )
    {
      response.getWriter().print( name + " = " + value + "\n" );
    }
  }



The PriorityQueue and GreaterEqualString classes are part of ObjectSpace's
free Java Generic Library:

  http://www.objectspace.com/products/jglOverview.htm



Erik

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to