Meaningless Drivel is fun!*
The moose likes Servlets and the fly likes request.getParameter is returning null value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "request.getParameter is returning null value" Watch "request.getParameter is returning null value" New topic
Author

request.getParameter is returning null value

Sunil Chavan
Greenhorn

Joined: Apr 11, 2007
Posts: 28
Hi,

I am invoking a servlet from jsp using post method on a websphere application server6. I have two text boxes (userid & password) on jsp whose values i require in a servlet. But in servlet request.getParameter(userid) or request.getParameter(password) returns me a null value.

My jsp code as follows -

Form declaration=
<form name=frmLogin method=post action="/QMS/QMSAuthServlet?val=12" >

[Note: /QMS is my context path]

Submit Button code=
<input type=image src="/com/images/submit.gif" width="58" height="13" border="0" onclickk="return check()">

Javascript function code=
function check(){
... some user input validation ...

document.frmLogin.submit();
return true
}

Web.xml code=
<servlet id="Servlet_1" >
<servlet-name > QMSAuthServlet</servlet-name >
<servlet-class > com.login.QMSAuthServlet</servlet-class >
</servlet >

<servlet-mapping id="ServletMapping_6" >
<servlet-name > QMSAuthServlet</servlet-name >
<url-pattern > /QMSAuthServlet</url-pattern >
</servlet-mapping >


If i change method from 'post' to 'get' then i able to get those values (userid & password) in servlet but the appended value while calling servlet (i.e. ?val=12) becomes null.

What exactly going wrong here. Do i need to specify defaultContext anywhere in web.xml? same code works fine in a another application where context path is '/' only whereas my application have 'QMS' as a context path.

Any help would be very much appreciated.

Thanks.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

Websphere, hardly a paragon of correctness, may be getting confused by the fact that you have a query parameter on your form action. What's up with that anyways? That's a really poor practice. I'd move that value to a hidden input.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sunil Chavan
Greenhorn

Joined: Apr 11, 2007
Posts: 28
Thanks for reply.

I've tried that but that doesn't solve my problem to get values of text fields in a servlet. It remains the same only.

Thanks and regards,
Anirvan Majumdar
Ranch Hand

Joined: Feb 22, 2005
Posts: 261
I have a vague feeling that in your servlet you might be trying to retrieve the paramters from the request object in the "doGet()" method. And in your "doPost()" you may not be calling the "doGet()" method.

That is why, perhaps, when you change your <form> tag's method from "POST" to "GET" you get the parameters, but not if the method is "POST".

Try inserting the line => doGet(reqObj, respObj); in your doPost method. One never knows what kind of miracle might be in store :roll:
[ April 10, 2008: Message edited by: Anirvan Majumdar ]
Sunil Chavan
Greenhorn

Joined: Apr 11, 2007
Posts: 28
I am retriving values in doGet method of servlet but i also calling doGet method in my doPost method as well.

doPost code=
doGet(rq, rp);
Sunil Chavan
Greenhorn

Joined: Apr 11, 2007
Posts: 28
Now i've made changes in my code to make things working.

I've removed image button and added submit button. Which will simply submit the form.

"Check" function is dropped now.

Also removed additional parameter ("?val=12") while invoking servlet.

Now it is a simple servlet which is getting invoked on click of submit button.

If method is "get" i am able to get values of text field in servlet but if method is "post" then i am not able to get those values. It gives me null values.

What makes "get" method to pass values and preventing "post" method to pass them.

Urgently require some help

Thanks in advance.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

At this point I'd use a tool that shows you the HTTP request and response structure to determine if the problem is on the client side or the server side. One example is Tamper Data.
Sunil Chavan
Greenhorn

Joined: Apr 11, 2007
Posts: 28
Any tool available for IE 6 or any other way to find it out. Tamper Data is for Mozilla.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

The LiveHeaders plugin and the FireBug plugin for FireFox can also show you this, as can any packet sniffer.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: request.getParameter is returning null value