good night!
I have three stringsString cosa1 = request.getParameter("cosa1").toString(); -> SALIDAS con números aleatorios (**LOS NÚMEROS SON IDS DE PRODUCTOS**): 4,3 - 3,4,5 - 1,5,4
I want to pass that data to three INT arrays in Java, I try this and it doesn't work:
String cosa1 = request.getParameter("cosa1").toString();
String cosa2 = request.getParameter("cosa2").toString();
String cosa3 = request.getParameter("cosa3").toString();
int cosa_1 = Integer.parseInt("cosa1");
int cosa_2 = Integer.parseInt("cosa2");
int cosa_3 = Integer.parseInt("cosa3");
It sends me the following error:
org.apache.jasper.JasperException: Ha sucedido una excepción al procesar la página JSP /registro/18-paso-23.jsp en línea 35
32: String cosa1 = request.getParameter("cosa1").toString();
33: String cosa2 = request.getParameter("cosa2").toString();
34: String cosa3 = request.getParameter("cosa3").toString();
35: int cosa_1 = Integer.parseInt("cosa1");
36: int cosa_2 = Integer.parseInt("cosa2");
37: int cosa_3 = Integer.parseInt("cosa3");
I hope you can help me, I already tried and I can't get my array of integers.
If the string has bad values like the , to make
cast
sure you'll get aNumberFormatException
as seems to be your case.To convert a
array
from integers there can be many ways but I will show two, iteratively and withStreams
(you must replace the variable a in by thing1, thing2, etc) also with the regular expression we avoid spaces, letters.Departure
Streams