J2EE: how to get into arraylist servlet passed in hidden field in JSP?

I'm looking for how to get my arraylist passed in a hidden field in my JSP to a servlet in a new arraylist. In my JSP:

    <input type="hidden" name="listHidden" id="listHidden" value="${myList}"/>

      

In my servlet, I tested this:

    String[] elementsList = request.getParameterValues("listHidden");

      

But the result is my list in the first element of the new table and I need a copy of the arraylist in the new arraylist because I have a way to do it with the elements of my list. What's the correct code?

+3


source to share


1 answer


If listHidden

is ArrayList<String>

, then you should be able to parse the input analysis, for example,

String str = "[string1,string2]";
            // ^--  or, request.getParameter("listHidden").toString();
String[] elementsList = str.substring(1, str.length() - 1).split("\\,");

      



It might be better to store these values ​​in Session

or in a database. Adding them to the form makes the request slower.

+2


source







All Articles