Showing posts with label Servlet interview questions. Show all posts
Showing posts with label Servlet interview questions. Show all posts

What is difference between PrintWriter and ServletOutputStream?

PrintWriter is a character-stream class where as ServletOutputStream is a byte-stream class.The PrintWriter class can be used to write only character-based information whereas ServletOutputStream class can be used to write primitive values as well as character-based information.

What is difference between forward() method of RequestDispatcher and sendRedirect() method ?


forward() methodsendRedirect() method
1) forward() sends the same request to another resource.1) sendRedirect() method sends new request always because it uses the URL bar of the browser.
2) forward() method works at server side.2) sendRedirect() method works at client side.
3) forward() method works within the server only.3) sendRedirect() method works within and outside the server.

What is the difference between doGet() and doPost()?


#
doGet()doPost()
1
In doGet() the parameters are appended to the URL and sent along with header information.In doPost(), 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.
2
The amount of information you can send back using a GET is restricted as URLs can only be 1024 characters.You can send much more information to the server this way - and it's not restricted to textual data either. It is possible to send files and even binary data such as serialized Java objects!
3
doGet() is a request for information; it does not (or should not) change anything on the server. (doGet() should be idempotent)doPost() provides information (such as placing an order for merchandise) that the server is expected to remember
4
Parameters are not encryptedParameters are encrypted
5
doGet() is faster if we set the response content length since the same connection is used. Thus increasing the performancedoPost() is generally used to update or post some information to the server.doPost is slower compared to doGet since doPost does not write the content length
6
doGet() should be idempotent. i.e. doget should be able to be repeated safely many timesThis method does not need to be idempotent. Operations requested through POST can have side effects for which the user can be held accountable.
7
doGet() should be safe without any side effects for which user is held responsibleThis method does not need to be either safe
8
It allows bookmarks.It disallows bookmarks.

What is the Servlet?

What is the Servlet?

A servlet is a Java programming language class that is used to extend the capabilities of servers that host applications accessed by means of a request- response programming model.