Using JSP, in my HTML, I have a form that I submit to another page. The form has a select list that has multiple elements. Before submitting the form, In java script, I make sure that all elements in the list are selected. Then I submit the form to the next page. In the next page, I assign selected values in the list to a java array. When I try to display the size of the array or any value in that array, I get Null Pointer Exception.
Here’s my form with the list:
<form name="inputGenesForm" id="test" method="POST" ACTION="result.jsp" enctype="multipart/form-data">
<div style=" position:absolute;top:6%;left:39%;">
...
...
<select id="inputSet2" multiple="multiple" style="position:absolute; top: 93px; left: 270px; width: 200px; height: 200px;">
In result.jsp,
<body background="image/geneBG.jpg">
<%
String [] selectedGenes= request.getParameterValues("inputSet2");
%>
<script>
alert(<%=selectedGenes.length%>);
</script>
Can anyone help? Thank you.
Error on submitting form to result.jsp:
type Exception report
message
descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: java.lang.NullPointerException
root cause
java.lang.NullPointerException
note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.1.2.2 logs.
request.getParameterValues() is not working in combination with “enctype=”multipart/form-data”