The code below is from a Servlet trying to read data from a submitted html form. The variable fieldValue is a String and prints correct value (like so BizStr: 5) but when I try to parse this value to integer, it does not print anything.
for(FileItem uploadItem : uploadItems){
if(uploadItem.isFormField()){
String fieldName = uploadItem.getFieldName();
String fieldValue = uploadItem.getString();
if(fieldName.equals("business_id")){
out.println("BizStr: "+ fieldValue +"\n");
out.println("BizInt: "+ Integer.parseInt(fieldValue )+"\n");
}
}
}
Why is this string not being parsed into integer?
Integer.parseIntthrows aNumberFormatException, which gets eaten somewhereout.println("BizInt: "+ Arrays.toString(fieldValue.toCharArray())+"\n");and edit what that does into your answerfieldValue.replaceAll("\\s","")(Note, that won't change the value of the variable, it will just return it. So you can use that code inside yourparseIntcall or dofieldValue = fieldValue.replaceAll("\\s","");)