• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regarding POST method.

 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm reviewing Whizlabs exam, there, I came across that,
POST data can only be read once
. Way is that? What's the impact?

Thanks!
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2419
95
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Abimaran,

I am not sure what they mean exactly, but maybe they refer to the following difference.
Consider a jsp like this:

and a simular jsp with calling the get method:

And a Servlet (with a correct mapping) which just forwards (from the doGet() and the doPost() method) to another jsp where it shows the text fields

If you now refresh the page which was made after a doGet() it just refreshes, but if you refresh the page after a doPost(), the browser will ask you if you want to re-submit your previous data (you can't re-read it)

Regards,
Frits
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Frits, this is the question. I don't know whether it's legal to post that question. Let's see what happens.




The html form accessed in a browser, and the value entered for value1 = 500, and value2 = 600. What will be displayed?

Thanks!
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2419
95
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abimaran,
I don't know whether it's legal to post that question. Let's see what happens.

As long as you provide the source of the question it is ok for javaranch (with the exception of real exam questions of course).

The html form accessed in a browser, and the value entered for value1 = 500, and value2 = 600. What will be displayed?
Is this also from Whizlabs?

Regards,
Frits
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yea, It's from Whizlabs. I mean, this is copyright version, so posting the question would make problem, that's why I asked it. There, they provide solutions, but, I couldn't understand.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2419
95
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
H Abimaran,

The question is testing the following rule:
  • either use the request.getParameter() or the request.getInputStream() to obtain the data being submitted but never use both.

  • Remember that request.getReader() is returning a BufferedReader which is just a wrapper around the InputStream

    Regards,
    Frits
     
    Abimaran Kugathasan
    Ranch Hand
    Posts: 2066
    Clojure IntelliJ IDE Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Frits! Normally, How does the container handles the request and response objects? For response, it's use the ServletOutputStream for writing binary data, and PrintWriter is a convenient way of writing, and PrintWriter is wrapped around ServletOutputStream. But what about request object? I know, there are two objetcts, ServletInputStream and BufferedReader. Defuulty, on which object is used to get the body of the request, such as getAttribute(), getParameter(), etc?

    Thanks!
     
    Frits Walraven
    Creator of Enthuware JWS+ V6
    Saloon Keeper
    Pie
    Posts: 2419
    95
    Android Chrome Eclipse IDE
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    For response, it's use the ServletOutputStream for writing binary data, and PrintWriter is a convenient way of writing, and PrintWriter is wrapped around ServletOutputStream. But what about request object? I know, there are two objetcts, ServletInputStream and BufferedReader. Defuulty, on which object is used to get the body of the request, such as getAttribute(), getParameter(), etc?

    For the request it is simular, you either use the getInputStream() which returns a ServletInputStream (just try it yourself and read the stream) or you use the convenient methods like getParameter() and getAttribute(). (the implementation of these methods probably use the getInputStream as well to obtain the data....)

    Regards,
    Frits
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic