Solved

req.getParameter gives me null

Posted on 2001-06-27
13
263 Views
Last Modified: 2010-03-31
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.
0
Comment
Question by:mehdi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 2

Expert Comment

by:jorj
ID: 6230772
some piece of code, maybe ? I'm not sure of what are you talking about...
0
 
LVL 1

Author Comment

by:mehdi
ID: 6230824
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
 
LVL 1

Author Comment

by:mehdi
ID: 6230827
i meant enctype :)
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 15

Expert Comment

by:mohan_sekar
ID: 6230830
hi,

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

bye
0
 
LVL 1

Author Comment

by:mehdi
ID: 6230862
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
 
LVL 2

Expert Comment

by:jorj
ID: 6231042
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
 

Expert Comment

by:berserks
ID: 6231480
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
 
LVL 2

Expert Comment

by:jorj
ID: 6231543
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
 
LVL 1

Author Comment

by:mehdi
ID: 6231551
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
 
LVL 2

Expert Comment

by:jorj
ID: 6231714
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
 
LVL 2

Expert Comment

by:jorj
ID: 6237063
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
 
LVL 5

Expert Comment

by:vemul
ID: 7616550
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
 

Accepted Solution

by:
modulo earned 0 total points
ID: 7639847
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ejb example issues 3 90
ejb mdb examples 1 39
jsp error 6 72
Session in java desktop 5 38
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question