Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

GET Method Working But POST is not

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Below is my form in a jsp, which on submit calls a servlet submit.do, 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
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My Servlet Code Is -


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



Vihan ...
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For Post method change your form tag as following
Use method="POST" then execute code

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

Regards
 
Vihan Srivastava
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
I suggest huckleberry pie. But the only thing on the gluten free menu is this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic