getParameterValues and setRequestProperty - multiple values
843841Nov 17 2003 — edited Jun 15 2007Hello,
I'm just getting into servlets, so any help here would be greatly appreciated...
I'm trying to create a simple servlet that accepts a String array as one of the request keys.
I have the following line in my Servlet, called myServlet:
String[] servletKeywords = request.getParameterValues("keywords");
I have tried using the following two approaches in my MIDlet code, but neither of them work:
Approach 1
-----------------
Using the setRequestProperty method...
HttpConnection con;
InputStream in;
String url = "http://localhost:8081/servlet/myServlet";
try {
con = (HttpConnection)Connector.open(url);
//con.setRequestMethod(HttpConnection.POST); //doesn't make any difference
con.setRequestProperty("keywords", "Barry,Alan,Rob");
in = con.openInputStream();
}
catch (etc.
.... but the servletKeywords String[] in myServlet is null.
Approach 2
-----------------
Creating the url manually, using commas to delimit the array elements...
HttpConnection con;
InputStream in;
String url = "http://localhost:8081/servlet/myServlet?keywords=Barry,Alan,Rob";
try {
con = (HttpConnection)Connector.open(url);
//con.setRequestMethod(HttpConnection.POST);
in = con.openInputStream();
}
catch (etc.
.... Using this method, the servletKeywords String[] does contain something, but it's:
servletKeywords[0] == "Barry,Alan,Rob"
not (as hoped for!):
servletKeywords[0] == "Barry"
servletKeywords[1] == "Alan"
servletKeywords[2] == "Rob"
I've spent all day trying to find an example of how to pass a String array to a servlet, but can't find it anywhere.
myServlet does work fine, it's just the getParameterValues (and setRequestProperty) that isn't working.
Can anyone give me an example of how to do it?
Thanks,
James