More problems with request.getParameter == null

T

Teresa Robinson

Hello again,

(hopefully the follow-ups have been taken care of: had to go into
agent.ini to get rid of the thing)

With your help, I was able to get the file upload code to work. Thank
you!

My new problem is in allowing the user to delete an uploaded file by
clicking a button at the end of the HTML row that contains that file
name. IE:

....
<%
for (int i=0; i < histid.size(); i++) {
html_hist = html_hist +
"<tr>" +
"<td>" +
filename
"</td>" +
"<td style=padding-left:0.3cm; padding-top:0.5cm>" +
"<form action=\"deleteconfirm.jsp\" method=\"POST\"
enctype=\"application/x-www-form-urlencoded\">" +
"<input type=\"submit\" name=\"delete\" value=\"Delete\" />" +
"<input type=\"hidden\" name=\"filename\" value= " +
filename + "> " +
"<input type=\"hidden\" name=\"hist_id\" value= " +
histid + "> " +
"<input type=\"hidden\" name=\"username\" value= " +
username + "> " +
"<input type=\"hidden\" name=\"state_name\" value= " +
state_name + "> " +
"</form>" +
"</td>" +
"</tr>";
}
....
%>
....

Clicking on the Delete button takes the user to a confirm page,
deleteconfirm.jsp, IE:

<%

String username = request.getParameter("username");
String filename = request.getParameter("filename");
String hist_id = request.getParameter("hist_id");
String state_name = request.getParameter("state_name");

%>
....
<form action="deleteuploadedfile" method="POST"
enctype="multipart/form-data">
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td>
Delete this file? (<%= filename %>)
</td>
<td>
<input type="hidden" name="username"
value= <%= username %> >
<input type="hidden" name="filename" value= <%= filename %>>
<input type="hidden" name="hist_id" value= <%= hist_id %>>
<input type="hidden" name="state_name"
value= <%= state_name %> >
<input type="submit" name="delete" value="Delete"/>
</td>
</tr>
<tr>
<td>
Cancel?&nbsp;&nbsp;&nbsp;&nbsp;
</td>
<td>
<input type="hidden" name="cancel" value="cancel" >
<input type="submit" name="cancel" value="Cancel"/>
</td>
</tr>
</table>
</form>
....

The deleteuploadedfile servlet is then supposed to delete the file
based on these parameters:

String filename = request.getParameter("filename");
String hist_id = request.getParameter("hist_id");
String username = request.getParameter("username");

but the parameters are null.


In debugging, I have found that the values somehow don't come through
to the servlet when the user clicks the Delete button. They are
correct throughout the whole process until then.

Does it have something to do with having many Delete buttons in the
Form action in deleteconfirm.jsp? I am blind at this point, so any
help is appreciated.

(and I know, you shouldn't do out.writes in jsp, it's what I thought
of at the time)

Thank you all in advance.
 
M

Manish Pandit

Hello again,

(hopefully the follow-ups have been taken care of: had to go into
agent.ini to get rid of the thing)

With your help, I was able to get the file upload code to work. Thank
you!

My new problem is in allowing the user to delete an uploaded file by
clicking a button at the end of the HTML row that contains that file
name. IE:

...
<%
for (int i=0; i < histid.size(); i++) {
html_hist = html_hist +
"<tr>" +
"<td>" +
filename
"</td>" +
"<td style=padding-left:0.3cm; padding-top:0.5cm>" +
"<form action=\"deleteconfirm.jsp\" method=\"POST\"
enctype=\"application/x-www-form-urlencoded\">" +
"<input type=\"submit\" name=\"delete\" value=\"Delete\" />" +
"<input type=\"hidden\" name=\"filename\" value= " +
filename + "> " +
"<input type=\"hidden\" name=\"hist_id\" value= " +
histid + "> " +
"<input type=\"hidden\" name=\"username\" value= " +
username + "> " +
"<input type=\"hidden\" name=\"state_name\" value= " +
state_name + "> " +
"</form>" +
"</td>" +
"</tr>";}

...
%>
...

Clicking on the Delete button takes the user to a confirm page,
deleteconfirm.jsp, IE:

<%

String username = request.getParameter("username");
String filename = request.getParameter("filename");
String hist_id = request.getParameter("hist_id");
String state_name = request.getParameter("state_name");

%>
...
<form action="deleteuploadedfile" method="POST"
enctype="multipart/form-data">
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td>
Delete this file? (<%= filename %>)
</td>
<td>
<input type="hidden" name="username"
value= <%= username %> >
<input type="hidden" name="filename" value= <%= filename %>>
<input type="hidden" name="hist_id" value= <%= hist_id %>>
<input type="hidden" name="state_name"
value= <%= state_name %> >
<input type="submit" name="delete" value="Delete"/>
</td>
</tr>
<tr>
<td>
Cancel?&nbsp;&nbsp;&nbsp;&nbsp;
</td>
<td>
<input type="hidden" name="cancel" value="cancel" >
<input type="submit" name="cancel" value="Cancel"/>
</td>
</tr>
</table>
</form>
...

The deleteuploadedfile servlet is then supposed to delete the file
based on these parameters:

String filename = request.getParameter("filename");
String hist_id = request.getParameter("hist_id");
String username = request.getParameter("username");

but the parameters are null.

In debugging, I have found that the values somehow don't come through
to the servlet when the user clicks the Delete button. They are
correct throughout the whole process until then.

Does it have something to do with having many Delete buttons in the
Form action in deleteconfirm.jsp? I am blind at this point, so any
help is appreciated.

(and I know, you shouldn't do out.writes in jsp, it's what I thought
of at the time)

Thank you all in advance.
--
Teresa Robinson
General Dynamics
Information Technology
Teresa.Robinson [at] gdit [dot] com

Get rid of enctype="multipart/form-data" from your form tag. Since you
are not uploading any files in the forms, this is not needed. Using
enctype of multipart renders the request to be multipart, which
explains getParameter() returning null.

-cheers,
Manish
 
T

Teresa Robinson

Get rid of enctype="multipart/form-data" from your form tag. Since you
are not uploading any files in the forms, this is not needed. Using
enctype of multipart renders the request to be multipart, which
explains getParameter() returning null.

Goodness, you are right, I didn't see that. I knew it was some little
thing I wasn't seeing.

Thank you so much, both of your comments have been spot on.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top