Professional Documents
Culture Documents
Q--Which code line must be set before any of the lines that use the PrintWriter?
A--setContentType() method must be set before transmitting the actual document.
Q--When a servlet accepts a call from a client, it receives two objects. What ar
e they?
A--ServeltRequest: which encapsulates the communication from the client to the s
erver.
ServletResponse: which encapsulates the communication from the servlet back to t
he client.
ServletRequest and ServletResponse are interfaces defined by the javax.servlet p
ackage.
Q--What information that the ServletResponse interface gives the servlet methods
for replying to the client?
A--It Allows the servlet to set the content length and MIME type of the reply. P
rovides an output stream, ServletOutputStream and a Writer through which the ser
vlet can send the reply data.
Q--What information that the ServletRequest interface allows the servlet access
to?
A--Information such as the names of the parameters passed in by the client, the
protocol (scheme) being used by the client, and the names of the remote host tha
t made the request and the server that received it. The input stream, ServletInp
utStream.Servlets use the input stream to get data from clients that use applica
tion protocols such as the HTTP POST and PUT methods
Q--What are the differences between GET and POST service methods?
A--A GET request is a request to get a resource from the server. Choosing GET as
the "method" will append all of the data to the URL and it will show up in the
URL bar of your browser. The amount of information you can send back using a GET
is restricted as URLs can only be 1024 characters. A POST request is a request
to post (to send) form data to a resource on the server.
A POST on the other hand will (typically) send the information through a socket
back to the webserver and it won't show up in the URL bar. You can send much mor
e information to the server this way - and it's not restricted to textual data e
ither. It is possible to send files and even binary data such as serialized Java
objects!