I have a question about programming Java into HTML using the latest version of Tomcat. I'm trying to get the option values from the HTML to go inside the Java program and print out said values. A friend of mine suggested that I create an array of strings and then print out from there, and I decided to take that advice, however I get the following error after the following code:
<form action="displayMusicChoices" method="post"> <--...some table code --> <td align="right" valign="top">I'm interested in these types of music:</td> <td> <select name="musicChoices" size="4" multiple> <option name="Rock">Rock</option> <option name="Country">Country</option> <option name="Bluegrass">Bluegrass</option> <option name="Folk">Folk</option> </select> </td> </tr> <tr> <td></td> <td><br><input type="submit" value="Submit"></td> </tr> </table> </form>
String choices = request.getParameterValues("musicChoices"); int select_choices = choices.length; ...///Other code out.println( "<!doctype html public \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n" ///Other ocde + "<p>We'll use this email to notify you whenever we have new releases ofr these types of music: </br>" for (int i =0; i <= select_choices; i++) out.print(choices[i] + " "); ///Print out selections
java.lang.NullPointerException DisplayMusicChoicesServlet.doPost(DisplayMusicChoicesServlet.java:61) javax.servlet.http.HttpServlet.service(HttpServlet.java:709) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
I can understand the NullPointerException, but I don't get HOW I can get it with this code unless it's not getting the option, which in that case I need advice on how to get said options.
Thanks for reading.