This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get POST data?  RSS feed

 
Rob Wehrstein
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm looking for a good, or elegant way to get the data payload from a POST request. I can do it using the following code


but I'm guessing that there's a better way. I'm looking for something of the form

I tried everything:

but none of these seem to work.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66182
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the content type?

Why do you need it as a block rather than (as usual) the individual parameters?
 
shivam singhal
Ranch Hand
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you need individual parameter then

request.getParameter("ParameterName");

ParameterName would be seted in your JSP sending request to the servlet.
is a good option.
 
Rob Wehrstein
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The block of parameters together represent one variable. I don't need to know what the individual parameters are. I think the content type is text/plain, but I'm not positive.
 
Dave Tolls
Rancher
Posts: 2909
35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the post data needs to be in the format as shown in your original method (as if it were the parameters of a GET) then I doubt very much you'll find a convenient method for that as POST data is not sent in that format.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66182
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Wehrstein wrote:The block of parameters together represent one variable. I don't need to know what the individual parameters are. I think the content type is text/plain, but I'm not positive.


Use the browser tools to inspect the HTTP requests. It will show you the heads and the body.

I'm still not 100% sure what you are actually trying to do.
 
Tim Holloway
Bartender
Posts: 18702
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can POST raw text (Content-type: text/text) and read the inputstream - likewise for XML, JSON, whatever, but when you POST from a form, the MIME encoding is something like X-FORM (don't ask me to get it precise, I'm too lazy ). And when one of those comes in, the server parses it and populates the HttpServletRequest with the form's name/value pairs. Which can be enumerated via the HttpServletRequest getParameterNames() method (or something like that.)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!