PDA

View Full Version : POST diff values, same name


rosentjl
04-17-2003, 02:40 PM
In the HTTP Request, I want to pass a few parameters, some of which have the same name and all of which have different values.

The GET version would be:
http://localhost:8080/pass?itemIDs=1111&itemIDs=2222&itemIDs=3333
in ActionScript this may be written:
getURL("http://localhost:8080/pass?itemIDs=1111&itemIDs=2222&itemIDs=3333","
_blank", "GET");

The closest that I have come to get a valid POST is:
var aLoadVars = new LoadVars();
aLoadVars.aDifParam="aaaa";
aLoadVars.itemIDs= "1111";
aLoadVars.itemIDs= "2222";
aLoadVars.send("http://localhost:8080/pass","_blank","POST"
);
However, this will overwrite the first value of itemIDs and will result in itemIDs=2222.

Supposedly, everything can be put into the HTTP header with:
var aLoadVars = new LoadVars();
aLoadVars.addRequestHeader("itemIDs","1111","itemIDs","2222");
aLoadVars.send("http://localhost:8080/pass","_blank","POST"
);
but my Java Servlet does not read these parameters.

The HTML equivalent is:
<html>
<body>
<form method="post" name="aForm"
action="http://localhost:8080/pass">
itemIDs = <input type="text" name="itemIDs" value="1111"><br>
itemIDs = <input type="text" name="itemIDs" value="2222"><br>
itemIDs = <input type="text" name="itemIDs" value="3333"><br>
videoID = <input type="text" name="aDifParam" value="aaaa"><br>
<input type="submit" value="post this">
</form>
</body>
<html>


any ideas? :confused:

_________josh

freddycodes
04-17-2003, 05:16 PM
You would need to POST an array to the servlet.


var aLoadVars = new LoadVars();
aLoadVars.aDifParam="aaaa";
aLoadVars.itemIDs = [];
aLoadVars.itemIDs.push("1111");
aLoadVars.itemIDs.push("2222");
aLoadVars.send("http://localhost:8080/pass","_blank","POST");

rosentjl
04-17-2003, 09:50 PM
Arrays are turned into comma-delimited Strings. I should have included this as one of my previous examples.
This code:
aLoadVars.itemIDs = [];
aLoadVars.itemIDs.push("1111");
aLoadVars.itemIDs.push("2222");
comes to the Servlet as:
aLoadVars.itemIDs="1111,2222"
Is it possible that this is a short-coming of ActionScript -- its inability to make a proper POST with parameters of the same name?

________josh

freddycodes
04-17-2003, 09:54 PM
Maybe I am misunderstanding, how would Java know the difference between the two, I mean how would you refer to each unique value, if they all had the same name, in most languages each assignment would override the previous value, I must be missing something on what you are trying to do.

rosentjl
04-17-2003, 10:12 PM
Java's ServletRequest.getParameterValues() documentation (http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/ServletRequest.html#getParameterValues(java.lang.S tring))
Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.
If the parameter has a single value, the array has a length of 1.

freddycodes
04-17-2003, 10:19 PM
That doesn't work, Java seems to be just creating the array for you. Is it possible to split string on commas in Java.

rosentjl
04-17-2003, 10:50 PM
Yes, I could definitely parse the String based upon commas. However, I opt not to take this route as I consider it less-good programming in that I would be making an exception for the (seeming) limitations of the ActionScript language. HTML can do this in both the GET and POST. So far, I can only get ActionScript to handle the GET.
I appreciate your willingness to continue to consider my dilemma.

__________josh

freddycodes
04-17-2003, 10:57 PM
Well I know very little about Java, a little about C# and a lot about PHP. While they are not the same, Java being an OOP programming language and PHP being a scripting language.

In PHP you cannot do this, and it appears actionscript also. If you had twoform fields with the same name in html and submitted the form via POST to PHP, only the last of the values would make it witout sending an array. Maybe that will shed some light on how to get it to work in Java.