drew drew - 4 months ago 8x
HTML Question

Weird issue when using HTML form to pass information to Java Servlet

Okay so I have two Java Servlets, one for letting the user select which images to delete (

) and another for actually deleting the images (
displays all the images in the container with a checkbox HTML form for the user to select which images to delete. Then, using POST the servlet passes that information along to
which iterates over which images it received and deletes them.

I actually had this working, but then I tried to change the structure of the code (have
forward to a .jsp file that output the HTML form which would then forward to
) but that didn't work out, so I'm trying to go back to the old way and now it's not working even though I'm pretty sure it's the same as I had before.


// retrieve image files
List<? extends SwiftObject> objs = os.objectStorage().objects().list("imageFiles");

out.println("<!DOCTYPE html><html><head><title>Object Storage - Delete</title><link rel='stylesheet' href='stylesheet.css' type='text/css' /></head>"
+ "<body>
<h1>Select images to Delete from container</h1>
<form method='POST' enctype='multipart/form-data' action='/ImageUpload/OSHandleDelete'>");

for (SwiftObject o : objs) {
// omitted code that gets the image's name, date last modified, and filepath (all Strings, I know this works)

out.println("<b>Name:</b> " + name + "<br/> <b>Time of Upload:</b> " + date + "<br/>"
+ "<input type='checkbox' name='"+name+"'> "
+ "<img src='"+filepath+"' alt='' style='max-width:800px;' /> <br/> <br/> <br/> ");

out.println("<input type='submit' value='Delete Images' /></form>");
out.println("</form> <br/> <br/> <div><br/><a class='return' href='index.jsp'><b>Click here to return home</b></a><br/><br/></div> <br/> <br/></body></html>");


Enumeration<String> parameterNames = request.getParameterNames();
if (!parameterNames.hasMoreElements())
System.out.println("no parameters (null)");

while (parameterNames.hasMoreElements()) {

String paramName = parameterNames.nextElement();
System.out.println("parameter: " + paramName);

String[] vals = request.getParameterValues(paramName);
if (vals == null)
System.out.println(" vals is null for " + paramName);
else {
for (int i = 0; i < vals.length; i++) {
System.out.println(" vals["+i+"]: " + vals[i]);

Right now I don't have
actually doing anything besides print statements. This is because I use
to find out whether the user checked image of
(i.e. if it's null it was not checked but if it's not null it was checked).

The HTML form displays perfectly with the images and everything. My problem is that no matter what's checked in the HTML form,
always prints to the console
no parameters (null)
meaning nothing was passed from
. I have a feeling the problem comes from either (1) the setAttribute statement in
or (2) something with the HTML form. I've done a lot of searching and I'm pretty confident what I have is right though and I really can't figure out what's causing this issue (especially since I'm pretty sure this is exactly what I had before and it worked). Does anyone have any ideas?


I found the error: I included enctype=multipart/form-data

Not exactly sure why that caused the error but I removed that part and now it's passing the parameters perfectly. Thanks for your help guys!