Can the servlet read values sent via hidden text fields ?

M

Madni

Hi all ,

I created a servlet that successfully gets the file using HTML input
type=file and saves it on the server. Now i also want to send some
other information using the same form i used to send the file. I want
to keep these fields hidden .But to my surprise i cudnt read neither
visible nor hidden control data in servlet . Can any one please guide
me in this .

Regards ,

Madni
 
T

Thomas Hawtin

Madni said:
I created a servlet that successfully gets the file using HTML input
type=file and saves it on the server. Now i also want to send some
other information using the same form i used to send the file. I want
to keep these fields hidden .But to my surprise i cudnt read neither
visible nor hidden control data in servlet . Can any one please guide
me in this .

The Servlet API will only give you the fields that occur before the
first file. The easiest way around it is to put the hidden fields above
the file.

Tom Hawtin
 
H

HalcyonWild

Thomas said:
The Servlet API will only give you the fields that occur before the
first file. The easiest way around it is to put the hidden fields above
the file.

Tom Hawtin

Hi Tom,

You mean to say, put the hidden fields above the form tag in HTML part,
is that so.
Also, I am not sure if that is an issue.

I have seen code earlier during maintenance, in which.
1. The hidden fields <input type="hidden" name="myname"
value="myvalue"> are at the bottom of the file.
2. The values are set by javascript code.
3. The servlet that is the target of the form is able to read the
hidden values.

I was using servlet 2.0/2.1 specs, not the current 2.4.

Thanks.
 
A

adamspe

what he's saying is:

<form method="POST" action="..." enctype="multipart/form-data">
<input type="hidden" ...>
<input type="file" ...>
<input type="submit" ... />
</form>

instead of:
<form method="POST" action="..." enctype="multipart/form-data">
<input type="file" ... />
<input type="hidden" ... />
<input type="submit" ... />
</form>

The order of the inputs in the form also dictates the order of the data
on the multipart stream posted to the server. For a servlet engine to
support reading of basic form input when a file precedes it on the
stream would require that the file be read off of the stream to get at
the next body part. Doing so automatically by a servlet engine is not
a particularly scalable possibility. As such I think it's pretty
common that an implementation only read form data off of the multipart
stream up to the first body part with a file content-disposition and
stop there. Only making available to the getParameter method
parameters either explicitly on the query args or in input preceding
the first file.
 
M

Madni

Dear ALL,

Thanks for positive response from all u guys ...I tried Thomas Hawtin
suggestion but unfortunately that didnt work .Any ways here is the
piece of code
<form id=form1 ENCTYPE="multipart/form-data" name=form1
action="http://192.168.0.132:8001/servlet/UploadTest" METHOD="POST"
onsubmit="return
oWESFWCoordinator.getObject('oUploadFile').validations();" >
.......
.......
<td class=label>Select the File:&nbsp;</td>
<input type=file NAME="File1" class=contentinput id=filepath
name=filepath maxlength=410 ></td>

<td><input type=text id=directory name="directory" >&nbsp;<input
type="button" class = configurationbutton value="Browse..."
id=btnSaveAs name=btnSaveAs
onclick="oWESFWCoordinator.getObject('oUploadFile').openWesBrowser()">
</td>
<td ><input type=text id="path" name="path" style="visibility:
hidden;"></td>
</table>

what i explored is , when I write hidden field above the file ... java
console (where i was looking for lot many System.out.println ....) was
showing that information(posted using hidden fields) prefixed with the
starting boundary of the file .(As u guys know each file is wrapped by
a boundary ,showing the file start and end ) ....
Similarly when i placed the hidden fields below the <input type = file
.....> , that hidden field values were then seen to be postfixed with
the closing boundary of the file .So i decided to parse the file string
, extract its boundary , and separating the value posted via hidden
field... Thats gonna get worked .
Again I would like to thank all you guys for helping me a lot ...God
bless u all

Best Regards ,
Madni
 
Joined
Jul 7, 2010
Messages
1
Reaction score
0
having same problem

sorry but i didnt get the solution , could you please post the code as well

it would be very helpful

thanks in advance
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top