• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

request.getParameter is returning null value

 
Sunil Chavan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sunil Chavan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any tool available for IE 6 or any other way to find it out. Tamper Data is for Mozilla.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The LiveHeaders plugin and the FireBug plugin for FireFox can also show you this, as can any packet sniffer.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic