Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

request.getParameterNames Ordering

Status
Not open for further replies.

Nescio

Programmer
May 22, 2003
7
CA
Hello forum readers,

I have a problem associated with the request.getParameterNames() method. I have a servlet that recieves a series of unknown parameter names and I would like to recieve these names in the order in which they appear on the form page. Now the request.getParameterNames() method will retrieve all of the parameter names, however, it seems that every time they are out of order :-S Is there any way to circumvent this problem? I reiterate that there is no way to know what the parameter names will be or name them in such a way that they can be alphabetically ordered.

thanks,

Nescio
 


Code:
<html>
<head>
	<script language=&quot;javascript&quot;>
		function goPost() {
			document.location = &quot;servlet/TestServlet?a=1&b=2&quot;;
		}
	</script>
</head>
<body>
	<form action=&quot;servlet/TestServlet&quot; method=&quot;POST&quot;>
		<input type=&quot;text&quot; value=&quot;value1&quot; name=&quot;param1&quot;>
		<input type=&quot;text&quot; value=&quot;value2&quot; name=&quot;param2&quot;>
		<input type=&quot;submit&quot; value=&quot;button 1&quot;>
	</form>

	<hr>
	<input type=&quot;submit&quot; onclick=&quot;goPost()&quot; value=&quot;button 2&quot;>
</body>



******************************************
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;


public class TestServlet extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			doPost(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println(&quot;query string is :: &quot; +request.getQueryString());
	}
}

So from the method getQueryString() you can split up the string yourself using the StringTokenizer class, and so retrieve the parameters in line. However, I did notive some odd behaviour - if you submit to the TestServlet class using javascript - all is fine, but if you do it from a form, the getQueryString() returns null. Obviously this will need looking at !
 
hmmm... thank you for the reply. I shall attempt to investigate further.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top