简体   繁体   中英

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

I search how to get my arraylist, passed in hidden field in my JSP, in 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 a new arraylist because I have a treatement to do on the elements of my list. What is the right code ?

If listHidden is an ArrayList<String> then you should be able to parse the input like,

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 the Session or in a database. Adding them to the form makes that request slower.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM