It would be great if answers were provided. Not the out of the book response, but real comments about how choices affect production by choosing one option over another. What are the best practices assoc. with each of these topics?
1 Q,..
Answer..
Advantegs of servlets over CGI are
1..servlets are multithreaded which can support multiple users requests ..
that is servlet is a resource and where as requests are treated as threads .so multiple requests (threads) can acess a single instance of servlet resource asynchronously ..where as CGI provide a new instance for every request it is a single thread model .By creating new instance every request server wont supprot multiple requests
2..servlets are used to generate dynamic content
3.. servlets are platform independent
4..servlets are more efficient compare to other server side programming
This answer is according to me ..you can find more on internet
2Q,.
Answer
Servlet is a server side component written in java ,which can host request of client , process the request and response sent back to the client
3Q,.
Answer
There are two types of servlets provided by servlet API those are
GenericServlet ..It can use for any type of protocols(http,ftp,telnet)
it is protocol independent ,it support service() method only
HttpServlet..It can use for only http protocol ,it support doGet() and doPost() methods with Service() methods
Q.9.What is the difference between GET and POST methods?
Using GET method,We can able to pass 2K data from HTML.
In POST method,We does not have any size limitation.
RE: What is the difference between Service, doGET, doP…
——————————————————————————–
when we make a request to any servlet, request doesn’t goes directly to the servlet instead it will go to the service method of the super class and then it was passed as a parameters to the service method of ur class.In doGet() method the data will append to the url as a querrystring and we can’t send huge amount of data using doGET() method. Where as in doPost()method the data can be directly sent to browser without displaying it in the url.withis we can send as much of data as we can.But doGet() method is little faster when compared to doPOst().but it is not recommended as for some sensitive messages like password will be displayed as a querrystring in it.
when method is GET browser appends request data as query string and is sent to server i.e request data is appended to URL, as the data is appended to URL secure information like passwords can be viewed by others which is displayed on address bar.As data is appended to URL large amounts of data cannot be sent to server
when methos is POST request information is sent to server as part of the body request so large amounts of data can be sent to server securely.
ANS-9 ) the get method is simple to handle it sends the data to server by adding data to URL of browser. so it has disadvantage that if your servlet is sending password that will be visible on browser… and there is restriction on the size of data that can be send by get Method..
but ib post methos the data gets ecoded in HTTP-streams and then send to server… so it has security features and size of the data that can be send is much more that in get menhod..
ans-17) session tracking means suppose if your site provide a login facility and it is accessed by many user at a time than you need a way to know request is coming from which user… so session tracking is needed we uses many methos for it like hidden fields,url rewriting , or APIS can be user.
URL rewriting is used when your site provides the facility of ANONYMOUS LOGIN
16 Comments on Basic Java servlet interview questions
It would be great if answers were provided. Not the out of the book response, but real comments about how choices affect production by choosing one option over another. What are the best practices assoc. with each of these topics?
1 Q,..
Answer..
Advantegs of servlets over CGI are
1..servlets are multithreaded which can support multiple users requests ..
that is servlet is a resource and where as requests are treated as threads .so multiple requests (threads) can acess a single instance of servlet resource asynchronously ..where as CGI provide a new instance for every request it is a single thread model .By creating new instance every request server wont supprot multiple requests
2..servlets are used to generate dynamic content
3.. servlets are platform independent
4..servlets are more efficient compare to other server side programming
This answer is according to me ..you can find more on internet
2Q,.
Answer
Servlet is a server side component written in java ,which can host request of client , process the request and response sent back to the client
3Q,.
Answer
There are two types of servlets provided by servlet API those are
GenericServlet ..It can use for any type of protocols(http,ftp,telnet)
it is protocol independent ,it support service() method only
HttpServlet..It can use for only http protocol ,it support doGet() and doPost() methods with Service() methods
4Q.,
Answer .
Http server request can sent in two types one is GET and second one is POST
sample code
it is used by html
Q.19.What are the methods in HttpServlet?
doGet()
doPost()
doHead()
doPut()
doOptions()
doDelete()
doTrace().
Both these classes are abstract.
Q.9.What is the difference between GET and POST methods?
Using GET method,We can able to pass 2K data from HTML.
In POST method,We does not have any size limitation.
Q.20.What are the types of SessionTracking?
1.Using Cookies
2.Using URL rewriting
3.Using HTTP session
4.Using Hidden form fields.
RE: What is the difference between Service, doGET, doP…
——————————————————————————–
when we make a request to any servlet, request doesn’t goes directly to the servlet instead it will go to the service method of the super class and then it was passed as a parameters to the service method of ur class.In doGet() method the data will append to the url as a querrystring and we can’t send huge amount of data using doGET() method. Where as in doPost()method the data can be directly sent to browser without displaying it in the url.withis we can send as much of data as we can.But doGet() method is little faster when compared to doPOst().but it is not recommended as for some sensitive messages like password will be displayed as a querrystring in it.
Servlet is a java program that is run inside a servlet engine called web server.It take requests from client and responds to those requests.
Life cycle of sevlet includes
init()–used for initialization
service()–for processing client requests
destroy()– used for closing
difference between GET and POST methods
when method is GET browser appends request data as query string and is sent to server i.e request data is appended to URL, as the data is appended to URL secure information like passwords can be viewed by others which is displayed on address bar.As data is appended to URL large amounts of data cannot be sent to server
when methos is POST request information is sent to server as part of the body request so large amounts of data can be sent to server securely.
5Q. what are the exceptions thrown by servlet
A. Exceptions thrown by servlet are:
ServletException
IOException
ANS-9 ) the get method is simple to handle it sends the data to server by adding data to URL of browser. so it has disadvantage that if your servlet is sending password that will be visible on browser… and there is restriction on the size of data that can be send by get Method..
but ib post methos the data gets ecoded in HTTP-streams and then send to server… so it has security features and size of the data that can be send is much more that in get menhod..
bye :- ajay
ans-17) session tracking means suppose if your site provide a login facility and it is accessed by many user at a time than you need a way to know request is coming from which user… so session tracking is needed we uses many methos for it like hidden fields,url rewriting , or APIS can be user.
URL rewriting is used when your site provides the facility of ANONYMOUS LOGIN
bye :- it’s ajay
What is meant by cookies? Why is Cookie used?
Ans: cookies are used to maintain small amount of data at client side.What
webserver is used for running the Servlets?
Ans: Mostly tomcat can be used to run the servlets and servlet will have presentation and business logic.