Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

Can the servlet read values sent via hidden text fields ?

Thread view: 
Madni - 21 Nov 2005 12:33 GMT
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
Thomas Hawtin - 21 Nov 2005 12:50 GMT
> 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
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

HalcyonWild - 21 Nov 2005 13:46 GMT
> > 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
[quoted text clipped - 8 lines]
>
> 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.
adamspe@gmail.com - 21 Nov 2005 20:08 GMT
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.
Madni - 22 Nov 2005 05:00 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.