File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Request.getparameter returning null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Request.getparameter returning null" Watch "Request.getparameter returning null" New topic

Request.getparameter returning null

Biju moozhikkara

Joined: Oct 21, 2005
Posts: 20
i have strange problem.iam calling a servlet from a jsp on submit.But when i use "POST" as method attribute in the form field, iam gettin null for the req.getparmeter() on the form text fields. And if i use GET iam getting null for the data i send along the URL. Can any body help me fix this. i want to read both the URL data and the text field data.
My project contain an index page which wil call a LoginServlet and it will redirect control to a home.jsp page.On presing enter on the screen produced by home.jsp another servlet will be called.Iam tryng to retrieve the data through request.getparameter in this servlet.
The entire problem started when i put the folowing code in my loginservlet.
String auth = request.getHeader("Authorization");
if (auth == null) {
resp.setHeader("WWW-Authenticate", "NTLM");
if (auth.startsWith("NTLM ")) {
byte[] msg = new sun.misc.BASE64Decoder().decodeBuffer(auth.substring(5));
int off = 0, length, offset;
if (msg[8] == 1) {
off = 18;
byte z = 0;
byte[] msg1 = {(byte)'N', (byte)'T', (byte)'L', (byte)'M', (byte)'S',
(byte)'S', (byte)'P', z,
(byte)2, z, z, z, z, z, z, z,
(byte)40, z, z, z, (byte)1, (byte)130, z, z,
z, (byte)2, (byte)2, (byte)2, z, z, z, z, //
z, z, z, z, z, z, z, z};
resp.setHeader("WWW-Authenticate", "NTLM "
+ new sun.misc.BASE64Encoder().encodeBuffer(msg1).trim());
else if (msg[8] == 3) {
off = 30;
length = msg[off+17]*256 + msg[off+16];
offset = msg[off+19]*256 + msg[off+18];
user = new String(msg, offset, length);
length = msg[off+1]*256 + msg[off];
offset = msg[off+3]*256 + msg[off+2];
user = new String(msg, offset, length);

[ March 11, 2006: Message edited by: Biju muzhikara ]
[ March 13, 2006: Message edited by: Biju muzhikara ]
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
If this was my problem I would do a view source on the HTML page that is sending the request. Check for things like: is the submit action really part of the form?
If that does not reveal the problem, I would dump the entire request to a log to see what is really being sent.
Biju moozhikkara

Joined: Oct 21, 2005
Posts: 20
function callPage(val){
var pgVal=formObj.pgValue.value;
var str=formName.substring(1,formName.length);
var temp = val;
if(temp == "7D") {
var entVal = formObj.WCMSCHLUES.value; formObj.action="../"+pgVal+"?pgValue="+pgVal+"&rwaid="+temp+"&WCMSCHLUES="+entVal;
else { formObj.action="../"+pgVal+"?pgValue="+pgVal+"&rwaid="+temp;
This is my script funtion which submit the form. i did put alerts just before submit to see whether the values are actually present.They values are present in the form object as it is submitted.
can the code i mentioned in the first post cause any problem.the entire thing is working fine if i remove it.
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

You should leave your form action to POST and use hidden tags to send the parameters.

(The necessity of the callPage() function is questionable)

[My Blog]
All roads lead to JavaRanch
Biju moozhikkara

Joined: Oct 21, 2005
Posts: 20
iam using POST and some of the fields in my form are hidden.
i have to use the script funtion ,since i have to decode which key the user pressed(seperate script function is used for it) and will pass a unique value to the callpage(var) for ex 7d for enter.
AnishK George

Joined: Mar 12, 2006
Posts: 5
Hi Biju

Can you please post the html code?

Also which part of this code is returning null for you?

Thanx and Regards,
Ansh K George
Biju moozhikkara

Joined: Oct 21, 2005
Posts: 20
java ranch is showing some error when try i to put jsp code.When i try with Post the field like <input type = 'hidden' name = 'pgValue' value = '<%=pgValue%>' > (for hidden and text fields)are returning null for req.getparameter().And if i try with GET the data i send along the url are not available.
[ March 17, 2006: Message edited by: Biju muzhikara ]
AnishK George

Joined: Mar 12, 2006
Posts: 5
Hi Biju,

If you give method='GET' url parameters will never be passed to server.
If you give method='POST' url parameter as well as the field values should be passed to the server. Please take the view source and see whether the hidden box is having some some value. Also please check whther the hidden field is inside the <form> tag.

Thanx and regards,
Anish K George
Shital Mahajan

Joined: Apr 23, 2007
Posts: 2
Is the problem solved?
I am also facing the same issue.
Please help.

I agree. Here's the link:
subject: Request.getparameter returning null
It's not a secret anymore!