I have an existing Java web application that has about 50 query parameters, similar to
http://localhost/myapp?a=1&b=2&c=3&d=4
and I extract values in my servlet using ServletRequest.getParameter, similar to
String a = req.getParameter("a");
Each of my existing parameters are single-valued. I now need to introduce a new parameter that is multi-valued. What is the best practice to do this with respect to the RESTful practices and the servlet specification?
I am considering the two options below, but if there's something better, please point it out.
Comma-Delimted Single Parameter
http://localhost/myapp?a=1&b=2&c=3&d=4&e=5,6,7,8
which would be encoded as
http://localhost/myapp?a=1&b=2&c=3&d=4&e=5%256%257%258
and be extracted as
String eStr = req.getParameter("e");
String[] e = eStr.split(",");
Multiple Parameters
http://localhost/myapp?a=1&b=2&c=3&d=4&e=5&e=6&e=7&e=8
which wouldn't need any special encoding and be extracted as
String[] e = req.getParameterValues("e");