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" >
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.
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.
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 ]
posted 10 years ago
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);
posted 10 years ago
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.