When I will prepare for technical interview, I have used to think about hints and opt technical terms.
So I have started preparing question while reading books. I will ask question my self and redo the answer until I get opt technical words.
This post all are my own preparation if any one find its use full I really deserve for that.
Visitors of my blogspot kindly add your valuable comments to improve my post.
Note:
If u find any answer is wrong let me know. So I can redefine the same.
- What is Servlet?
- Servlet is a java program, It will run inside the web container
- Servlet extends request/respond –oriented servers such as java oriented web server.
- Different way to session tracking?
- Cookies
- URL re-writings
- Http session tracking
- Hidden form
- Session
- What mechanism is used by servlet container to maintain the session?
- Session
- Cookies
- URL re-writing
- Difference between GET and POST?
No. | Get | Post |
1 | Data are submitted part of URL | Data are submitted inside body of servlet request. |
2 | Query max length is 255 character | No Limitation |
3 | Its not secure | Its secure. |
- Session
- Session is a object is used to track the information about the user with web application across multiple HTTP Request (State less).
- Session is stored on web server.
- Servlet Mapping
- Mapping defines the association between the URL pattern and Servlet
- Mapping will be define in web.xml
- Mapping is used to map the particular request to Servlet.
- Servlet Context:
- It’s a servlet Object that contains information about web application and container.
- Each application has only one servlet Context Object.
- Uses for set the attribute that other servlet in the same context can use.
- Can we use constructer instead of Init():
- Yes we can use constructer in Servlet
- But we wont get servlet specific feature
- So we can’t use servletcontext and servletconfig object in constructer.
- Life cycle method of the servlet:
- Javax.servlet.Servlet interface providing 3 life cycle methods are
- Public void init (ServletConfig config)- will be called when instance is created.
- Public void service(ServletRequest req,ServletResponse res)-Every request is handled by service method only.
- Public void distory()-when object is de-allocated from JVM.
- Pre Initialization of a servlet:
- Process of loading servlet before any request comes in is called pre loading/pre initialization.
- We have to include the element
priority for every servlet in web.xml - Difference between HttpServlet and Generic Servlet:
No. | Http Servlet | Generic Servlet |
1 | Parrent Class for Http Servlet is Generic Servlet | Parent class of HttpServlet is Servlet |
2 | Http Servlet support doget(),dopost(),doHead methods | Service method will handle all the request. |
- Difference between ServletContext and ServletConfig:
No. | Servlet Context | Servlet Config |
1 | Set of methods support to communicate with servlet container | Its specific to the single servlet. |
2 | Uses for set the attribute that other servlet in the same context can use. | Its used to initialize the servlet specific value. |
3 | It’s created when servlet container created. | It’s created when specific class is loaded by container. |
- Advantages and selling point of Servlet?
- Servlet handle the multiple requests and synchronize the request.
- This allows servlet to support online real time conferencing.
- Servlet forward the request to the other servlet.
- So servlet can be used to balance the load among several servers that mirror the same content.
- what are the Information servletRequest object contain:
- parameter passed by the client
- name of the remote host
- the protocol
- Type of constraints send on the client : by servlet Response interface
- Content length
- Content type
- Servlet Writer, Servlet output stream and a writer through which the servlet can send the data.
- Context Initialization Parameter:
- It’s specified in web.xml under the
element. - This is a parameter for the whole application not specific for Servlet/JSP.
- It will be only accessed by servlet context object.
- Servlet Chaining:
- Two are more servlet co-operate in servicing a single request.
- Difference between Servlet Context and Page Context?
- ServletContext –Gives information about Servlet container
- PageContext-Gives information about request
- Difference:
- Request.getRequestDispacher()-Need to give relative path.
- Context.getRequestDispacher()-Need to give absolute path.
- Difference:
- RequestDispacher()-Direct with request and Response object.
- sendRequest()-direct with new request and Response object.