File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes GET Method Working But POST is not Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "GET Method Working But POST is not" Watch "GET Method Working But POST is not" New topic

GET Method Working But POST is not

Vihan Srivastava

Joined: Aug 05, 2008
Posts: 3
Below is my form in a jsp, which on submit calls a servlet, at the moment the servlet is using GET method and in servlet I am able to getParameters for both textarea and the hidden control, but when I make it to post, it returns null for both of the parameters, I have no idea why.

Please help me with this, i am really puzzled with this

Vihan ...
Vihan Srivastava

Joined: Aug 05, 2008
Posts: 3
My Servlet Code Is -

For Get Method Values are printed but for Post its printing null and null.

Vihan ...
Sagar Birari

Joined: Sep 05, 2008
Posts: 11
For Post method change your form tag as following
Use method="POST" then execute code

<form name="form1" method="POST" action="/Ideas/">


Sagar Birari
Development & Technical Blog
Vihan Srivastava

Joined: Aug 05, 2008
Posts: 3
Thanks Sagar For the Reply,

Obviously i tried with POST only and it was not working, with GET its working.

I was debugging the problem just now and found an interesting behavior.

I modified servlet code and added RequestDispatcher at the end and forwarded the request to a JSP as -

(i have excluded the irrelevant code here)

Now when i ran the prog in debug mode, i saw that after request is dispatched to jsp the doPost is called again, and this process repeats exactly three times, and the most interesting part is that in second time i can see the parameters being returned properly but in the first and third it is not.

Do you have any idea why this is so?

Appreciate your co-operation
Amit Ghorpade

Joined: Jun 06, 2007
Posts: 2709

Hi Vihan Srivastava welcome to Javaranch

Not a good programming practice to print to the output, forward and then close the stream.
If the forward works, then your POST is working, isn't it?

|Asking Good Questions|
I agree. Here's the link:
subject: GET Method Working But POST is not
Similar Threads
how do I submit without a submit button textarea contents
Form Plugin Form Reference On Success callback
Querystring not working
Need help to display a confirmation message after the form submission
jQuery select option