tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Greg Trasuk" <>
Subject RE: Ordering of parameters in HTTPRequest Object
Date Mon, 16 Jul 2001 19:45:28 GMT
	You'd parse the message body into an ordered list of parameters (pick your
favourite Collections object -  mine would probably be an ArrayList in this
case), then drop that collection into the Request object with
request.setAttribute(...) if you were forwarding the request to other
servlets.  Otherwise, you'd just use the collection in the same servlet you
parsed it from.

	I don't know whether you'd be able to reset the input stream (with the
reset() method) to the beginning and re-read the request body - the API
specs don't quite say, although they do say that you can only call
getInputStream() once.  I wouldn't count on being able to re-read it.  I
would also expect that once you used getInputStream(), you would not be able
to use getParameter(), and vice-versa.  According to the API docs, "If the
parameter data was sent in the request body, such as occurs with an HTTP
POST request, then reading the body directly via getInputStream() or
getReader() can interfere with the execution of this method."

Good luck,

Greg Trasuk, President
StratusCom Manufacturing Systems Inc. - We use information technology to
solve business problems on your plant floor.

-----Original Message-----
From: Sean Tiley []
Sent: Monday, July 16, 2001 2:00 PM
Subject: RE: Ordering of parameters in HTTPRequest Object

Thanks very much...
I will look into the getInputStream().  It seems reasonable, but then wont I
have to pass this around with the request object?


>From: "Greg Trasuk" <>
>To: <>
>Subject: RE: Ordering of parameters in HTTPRequest Object
>Date: Mon, 16 Jul 2001 12:37:16 -0400
>	I agree with Michael, it's not a great idea to depend on the order of the
>request parameters.  It makes the code more fragile and less resilient to
>maintenance.  For example, you might want to change the layout of the form
>to improve usability or change the aesthetics, which would change the order
>in which the controls appear, and hence the order in which the fields are
>submitted, which breaks your servlet.
>	Far better to name the parameters.  If naming is not possible, you might
>want to look into reading the request body directly using the
>ServletRequest.getReader() or ServletRequest.getInputStream() methods.  You
>would then need to parse the data to extract the parameters.  I would
>imagine that you could find similar code in the Tomcat sources, but it's
>still going to be some work.
>Greg Trasuk, President
>StratusCom Manufacturing Systems Inc. - We use information technology to
>solve business problems on your plant floor.
>-----Original Message-----
>From: Michael Wentzel []
>Sent: Monday, July 16, 2001 8:39 AM
>To: ''
>Subject: RE: Ordering of parameters in HTTPRequest Object
> > Hello all, I am new to this mailing list, and Tomcat, so please pe
> > patient...
> >
> > I am using Servlets to recieve html form submissions.
> >
> > Problem is that the form fields are in a particular order on
> > the form, but
> > when I get the Parameters from the request object this field order is
> > gone...
> >
> > The post data comes in in the proper order, but I can not recover the
> > ordering.  If it was only 1 form I was dealing with, I could
> > write code to
> > format a response, but the app is very generalized, and it is
> > designed to
> > handle many different forms.
> >
> > So the question.   Is there no way in tomcat to preserve the
> > ordering of
> > parameters from a form submission?
>No.  This is servlet API thing, not a tomcat thing.  I think it's a bad
>idea to develop servlet to depend on the order in which a request object
>is formed because you never know for sure that an ordering is going to
>be fixed.  For example, say a hashing algorithm is used for speed up
>access.  How do you order the elements of a hash table?  The only thing
>I could suggest is preface every form element with its' order, 1st element
>would be 0_elementname and 9th element would be 8_elementname, then order
>the elements yourself, but I think this is kind of sloppy.
>Michael Wentzel
>Software Developer
>Software As We Think -

Get Your Private, Free E-mail from MSN Hotmail at

View raw message