0 Replies - 608 Views - Last Post: 23 June 2013 - 12:24 AM

#1 Gisengryl  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 125
  • Joined: 08-September 12

Obtaining a set of array values from a enctype multipart form.

Posted 23 June 2013 - 12:24 AM

A checkbox will have multiple values if the user checks more than one option. I am trying to retrieve the array of checked values.

Previously, without the enctype multipart, a getParameterValues() would have done the job.

I am using enctype multipart because there's a file upload option involved. I am using the Apache FileUpload API.

Logic :
I did a check if it is a form field, and then as long as the form field name matches the name of the checkbox 'genreList' , it will keep extracting the checkbox parameters out.

The checkbox params are then inserted into a ArrayList for further manipulation.

However, my current method of extracting the multiple checkbox values doesn't work.

Any help is very much appreciated :surrender:/>

Relevant HTML code:

	<form  action="DataAdd.jsp" method="post" enctype="multipart/form-data">
	
	<!------------------------ Normal Form Fields -->
	<td>Release Date</td>
	<td><input type='text' size=30 name='date'></td>

	<td>Apple</td>
	<td><input type='text' size=30 name='apple'></td>

	<!-------------------------- Checkbox ---------------------------------------->
	<td>Genre:</td>
	<td><input type='checkbox' name='genreList'> " + genreName + " </td>

	</form>


Relevant JSP code:

String getRelDate 	= "";
	String getApple 	= "";

      try{ 
         // Parse the request to get file items.
         List<FileItem> items = upload.parseRequest(request);

         // Process the uploaded file items
         Iterator<FileItem> i = items.iterator();

         while ( i.hasNext () ) 
         {
        	FileItem fi = (FileItem) i.next();
        	
		if ( fi.isFormField () ){
			fi.getFieldName().equals("date");
			getRelDate = fi.getString();
			
			fi.getFieldName().equals("apple");
			getApple = fi.getString();

			// get params from checkbox named 'genreList'   
			// This doesn't work. 
			fi.getFieldName().equals("genreList");
			String getGenre = fi.getString("genreList");
			// adds each checkbox param to ArrayList 'genreTick' 
			genreTick.add(getGenre);
		}


    	}
}


Is This A Good Question/Topic? 0
  • +

Page 1 of 1