Hi,
You can include within "fact_name" field not only the type of the form
to be submitted but also the fields it should contain in the order you
need to read them.
By using a comma (or other) sepparator, and a StringTokenizer to
get the "fact_name" name *and* the field names you expect to retrieve
within current fact:
<INPUT TYPE="hidden"
NAME="fact_name"
VALUE="user_profile,country,sex,age,hiv_status"
>
... followed by fields named "country", "sex", "age", and others no matter
their order..
----------------
And use it within servlet's doPost(req,res):
...
StringTokenizer st = new
StringTokenizer(req.getParameter("fact_name"), ",");
String factName = st.nextToken();
/** Now you know the factName first. */
// ....
String name = null; String value = null;
while(st.hasMoreTokens()) {
name = st.nextToken();
value = req.getParameter(name);
...
}
----------
You've got them.. no?
Cezar Totth
On Thu, 12 Aug 1999, Andy Bailey wrote:
> > Hmm .. how about using an array to keep track of the parameters passed to
> POST
> > and renaming all your form elements to "form_input", then you could use:
> >
> > String sInputValues[] = (String []) req.getParameterValues("input");
> >
> > And rearrange the input anyway you'd like. Just an idea.
> >
> > - Jon
>
> Doing this is a very bad idea because you will lose context information
> about which parameter has which value.
>
> > Message UK wrote:
> >
> > > Hi there.. I have a problem with getting parameters in a servlet -
> > > specifically the order in which my parameters are submitted. My html
> code is
> > > as follows (abbreviated):
> > >
> > > <FORM NAME="user_profile" ACTION="../servlet/MyServlet3" METHOD=GET
> > > TARGET="_self">
> > >
> > >
> > > <SELECT NAME="country"><OPTION VALUE="uk"> UK etc.,</SELECT>
> > >
> > > <INPUT TYPE="radio" NAME="hiv_status" VALUE="HIV positive"> HIV
> positive<BR>
> > > etc.,
> > >
> > > <SELECT NAME="age"><OPTION VALUE="under 18"> under 18 etc.,</SELECT>
> > >
> > > <INPUT TYPE="radio" NAME="sex" VALUE="female"> female<BR>
> > >
> > > <INPUT TYPE="submit" VALUE="submit"></FORM>
> > >
> > > and my servlet code needs the HIDDEN field (fact_name) to be retrieved
> > > first:
> > >
> > > Enumeration enum = req.getParameterNames();
> > > String name = null;
> > > String value = null;
> > >
> > > while (enum.hasMoreElements())
> > > {
> > > file://gets each parameter one at a time
> > > name = (String) enum.nextElement();
> > > value = req.getParameter(name);
> > >
> > > out.println(name + value + "\n");
> > > <snip>
> > >
> > > try{
> > > file://use first parameter to name the fact
> > > if("fact_name".equals(name)){//i.e. the parameter is the name of the
> fact
> > > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > > <snip>
> > >
> > > this code above relies on the hidden field in my html code being the 1st
> > > parameter retrieved...
> > >
> > > but I'm actually getting the parameters in this order (when I print them
> out
> > > after the value = req.getParameter(name); (see above):
> > >
> > > 1.hiv_status
> > > 2.country
> > > 3.age
> > > 4.sex
> > > 5.fact_name
> > >
> > > Does anyone know how to control the order in which parameters are
> submitted,
> > > or any other help as to what I'm not doing?? Many thanks! D Lampon
> > >
>
> There is no guaranteed order in which parameters are provided by the request
> object or the browsers and neither
> is it important.
>
> The only order that mattes is the order in which you retrieve them.
>
> So in order to achieve the effect of ordering that you seem to need you can
> simply do the following
>
> // 1st parameter to be retrieved is
>
> String factName = request.getParameter("fact_name");
>
> // And retrieve your parameters in any order you wish.
>
> If you wanted to you can force order like this
>
> String parametersInOrder[] = {"fact_name", "hiv_status", "country", "age",
> "sex"};
> String parameterValuesInOrder = new String[paramtersInOrder.length];
> for(int i=0;i<parametersInOrder.length;i++) {
> parameterValuesInOrder[i] = request.getParameter(parametersInOrder[i]);
> }
>
> A word of caution though, you should never rely on any of the parameters
> being present or having valid values.
> ALWAYS check for null and invalid values for parameters before using them.
>
> Remembers, the order in which parameters are accessed can and should be
> determined by you, not the browser and not the
> form.
>
> Hope this helps
>
> Andy Bailey
___________________________________________________________________________
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