aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes regarding POST method. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "regarding POST method." Watch "regarding POST method." New topic
Author

regarding POST method.

Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

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!


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1675
    
  25

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

Joined: Nov 04, 2009
Posts: 2066

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
Bartender

Joined: Apr 07, 2010
Posts: 1675
    
  25

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

Joined: Nov 04, 2009
Posts: 2066

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
Bartender

Joined: Apr 07, 2010
Posts: 1675
    
  25

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

    Joined: Nov 04, 2009
    Posts: 2066

    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
    Bartender

    Joined: Apr 07, 2010
    Posts: 1675
        
      25

    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
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: regarding POST method.