Skip 2D array in querystring for JSP

I would like to create a 2D array in the query string and pass it to JSP. I could add strings, but I could not find the syntax for adding two-dimensional arrays.

Example:

HTTP: // local: 8080 / queryWithQueryString twodArray [0] [0] = StoreID & twodArray [0] [1] = 101

How can i achieve this?

0
source share
1 answer

You can just use it as is. The parameter name will arrive literally in that form. JSP has no special treatment for this (unlike, for example, PHP). Therefore, you will need to disassemble yourself.

String[][] twodArray = new String[1][]; twodArray[0] = new String[2]; twodArray[0][0] = request.getParameter("twodArray[0][0]"); twodArray[0][1] = request.getParameter("twodArray[0][1]"); 

It might be easier to use standard HTTP conventions for multiple parameter names.

HTTP: // local: 8080 / queryWithQueryString twodArray [0] = StoreID & twodArray [0] = 101

with

 String[][] twodArray = new String[1][]; twodArray[0] = request.getParameterValues("twodArray[0]"); 

It is probably easier to use List<String[]> instead of String[][] , since List can expand dynamically. This is useful if you do not know the number of items in advance.

 List<String[]> twodArray = new ArrayList<String[]>(); for (int i = 0; i < Integer.MAX_VALUE; i++) { String[] values = request.getParameterValues("twodArray[" + i + "]"); if (values == null) break; twodArray.add(values); } 
0
source

Source: https://habr.com/ru/post/1448092/


All Articles