req.getParameter gives me null

I found a script for a file Upload, it works fine (by the way, its a servlet).  

The problem that I have is that I can *only* get the contents of the file field! req.getParameter("");

I have seen this problem before ( and i noticed that it seemed to be because of the enctype being set to multipart form data.

How do I get values of other fields from my Servlet ?

cheers.
LVL 1
mehdiAsked:
Who is Participating?
 
moduloConnect With a Mentor Commented:
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0
 
jorjCommented:
some piece of code, maybe ? I'm not sure of what are you talking about...
0
 
mehdiAuthor Commented:
Here is the exact code !

http://home.swipnet.se/~w-50670/yafus.html

its works perfectly, but.. if I have another Form element (input type of text), i can not retrieve its value from the servlet, it returns null (req.getParameter does not work with the nectype of the form)

~~~~~~~~~~~~~~~~~~~~~~~~~~~
The secret lemonade drinker
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
mehdiAuthor Commented:
i meant enctype :)
0
 
mohan_sekarCommented:
hi,

   I am not getting ur question dear. More elaborate, better with some piece of code

bye
0
 
mehdiAuthor Commented:
umm.. ok..

See the link that I sent you.  That is the code.  It works fine.

I want to add to the servlet in question to get other inputs from the form aswel.. (imagine I also had <input type="text" name = "NAME" value="THIS IS A VALUE"> )

so, where in the servlet (SEE LINK I POSTED) it says

HTMLout.println("<center><h2>The file \'"+FileName+"\' has been uploaded.</h2></center>");

I want to retrieve the value of another HTML element (NAME, above) within my servlet.. so I change the above line to:

HTMLout.println("<center><h2>The file \'"+FileName+"\' has been uploaded.  Your name is " + _req.getParameter("NAME") + "</h2></center>");

my problem is that _req.getParameter("NAME") gives me null.

Im sorry if that is not clear enough, I have explained it ad nausia now :]

~~~~~~~~~~~~~~~~~~~~~~~~~~~
The secret lemonade drinker

0
 
jorjCommented:
A quick advice:
do a test by printing all information you receive and see if the parameter you are looking for is sent.

Enumeration eHeader = request.getHeaderNames ();
while(eHeader.hasMoreElements ())
{
     String key = (String)eHeader.nextElement ();
     String value = request.getHeader (key);
     System.out.println ("\t" + key + " : " + value);
}

Do the test also with request.getAttributeNames() and request.getParameterNames() and you will see if and where is what you are looking for.

0
 
berserksCommented:
It cannot be done.  You have 2 different forms and you're only submitting one form.  In order for a servlet to be able to retrieve data from a form, you'll have to submit it to the servlet.  

One way I would suggest is to write an onclick that submits both forms, then you can probably retrieve data from both forms.  If that doesn't work, you'll have to submit the first form to the second form, retrieve data from the first form in the second form, and submit the second form.
0
 
jorjCommented:
Of course he can't with two different forms, but I believe he would want to add new elements to the same form and here is where he's in trouble.
0
 
mehdiAuthor Commented:
jorj

Yes, thats where the problem lies ! I have solved this bu doing the upload completely seperately (as seenon hotmail, yahoo etc).  I never had this problem in Perl.  CGI.pm always took care of this.
0
 
jorjCommented:
So you actualy don't know where were you stack in ? Because if you do, please let an answer for those to come.

Hope I was useful.
0
 
jorjCommented:
Your problem was one I was interested in and never had the time to implement it. So I decided to study what's going on there and here is the complete answer (not for points but for future references).

The protocol:
http://www.w3.org/TR/1998/REC-html40-19980424/interact/forms.html#h-17.13.4.2

In html file:
<INPUT TYPE="hidden" name="ascuns" VALUE="myvalue">
TYPE can be TEXT also. You forgot to close the FRAME tag in the example you gave us !


Result, as it is received char by char, except the "Headers: and "Body:" labels. As you see you can send as many parameters as you want and you'll find them in the same way as you have found the filename.

Headers:
     Accept : image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/pdf, */*
     Accept-Language : en-us
     Content-Type : multipart/form-data; boundary=---------------------------7d13422aa05de
     Accept-Encoding : gzip, deflate
     User-Agent : Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)
     Host : localhost:8080
     Content-Length : 757
     Connection : Keep-Alive

Body:

-----------------------------7d13422aa05de
Content-Disposition: form-data; name="upload"; filename="C:\FileUpload\test.xxx"
Content-Type: text/html

text-file-content-here

-----------------------------7d13422aa05de
Content-Disposition: form-data; name="ascuns"

myvalue

-----------------------------7d13422aa05de--
0
 
vemulCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
- To be PAQ'ed and points refunded
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

vemul
Cleanup Volunteer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.