SERVLETS AND JSP INTERVIEW QUESTIONS AND ANSWERS PDF
Top 50 Servlet Interview Questions & Answers . it contains one or more containers such as EJBs, Servlet, JSP containers. Download PDF. Top 50 JSP Interview Questions & Answers JSP is a standard extension of Java and is defined on top of Servlet .. interview. Download PDF. Dear readers, these JSP Interview Questions have been designed specially to get you continue based on further discussion and what you answer: JavaServer Pages are built on top of the Java Servlets API, so like Servlets, JSP also has.
|Language:||English, Spanish, Portuguese|
|Genre:||Academic & Education|
|ePub File Size:||MB|
|PDF File Size:||MB|
|Distribution:||Free* [*Regsitration Required]|
Here I am providing a list of 50 servlet interview questions with answers to help . Java provides web application support through Servlets and JSPs that can run . 50 Servlet Interview Questions and Answers _ sppn.info - Download as Java provides web application support through Servlets and JSPs that can run in . JSP Interview Questions and Answers. What is a JSP and what is it A JSP compiler is used in the background to generate a Servlet from the JSP page. What is.
ServletContext is enhanced in Servlet Specs 3 to introduce methods through which we can programmatically add Listeners and Filters and Servlet to the application. When we want some init parameters to be available to multiple or all of the servlets in the web application. Servlet containers may also provide context objects that are unique to a group of servlets and which is tied to a specific portion of the URL path namespace of the host.
We can use getServletConfig method to get the ServletConfig object of the servlet. ServletContext interface provides access to web application parameters to the servlet. ServletResponse response — includes the content of a resource servlet. We can also use this to include the content of another resource to the response.
ServletResponse response — forwards the request from a servlet to another resource servlet. HTML file in the response. What is Request Dispatcher? ServletConfig is a unique object per servlet whereas ServletContext is a unique object for complete application. This interface is used for inter-servlet communication in the same context. JSP or another servlet in same application. There are two methods defined in this interface: ServletConfig is used to provide init parameters to the servlet whereas ServletContext is used to provide application level init parameters that all other servlets can use.
JSP file. JSP page. PrintWriter is a character-stream class whereas ServletOutputStream is a byte-stream class. IllegalStateException at runtime with message as other method has already been called for this response. We can create deadlock in servlet by making a loop of method invocation. We can use PrintWriter to write character based information such as character array and String to the response whereas we can use ServletOutputStream to write byte array data to the response. However SingleThreadModel does not solve all thread safety issues.
For example. These classes are not used in normal servlet programming. When servlet container receives client request. The whole purpose of service method is to forward to request to http: Also it takes out all the benefits of multithreading support of servlets. These wrapper classes are provided to help developers with custom implementation of servlet request and response types. We can extend these classes and override only specific methods we need to implement for custom request and response objects.
When we want to invoke another servlet from a servlet service methods. Ideally if we have to initialize any resource for servlet. If we have to do some pre-processing of request. We can invoke another servlet using RequestDispatcher forward and include methods and provide additional attributes in request for other servlet http: There are three scopes for servlet attributes — request scope.
If there are any local variables in service methods. Servlet attributes are used for inter-servlet communication. HttpServlet init method and destroy method are called only once in servlet life cycle. The thread safety mechanisms are similar to thread safety in standalone java application.
But service methods such as doGet or doPost are getting called in every client request and since servlet uses multithreading.
If we have to forward the request to a resource in another application. If we have to send some data also. RequestDispatcher forward is used to forward the same request to another resource whereas ServletResponse sendRedirect is a two step http: We can use RequestDispatcher forward method to forward the processing of a request to another servlet. If we want to include the another servlet output to the response.
This sends the response to client with response code as to forward the request to another URL. Read more about abstract class. In sendRedirect. We know that Servlet Container manages the life cycle of Servlet. In forward browser is unaware of the actual processing resource and the URL in address bar remains same whereas in sendRedirect URL in address bar change to the forwarded resource.
The request sent is a completely new request. Request Handling — Once servlet is initialized. This is the place where a servlet class transforms from normal class to servlet. Servlet Life Cycle consists of three methods: For every client request. Servlet Class Initialization — Once the servlet class is loaded. Servlet Class Loading — When container receives request for a servlet. Removal from Service — When container stops or we stop the application.
ServletResponse response — This method is called once for every request. If we override init ServletConfig config method. What is URL Encoding? URL Encoding is the process of converting data into CGI form so that it can travel across the network without any issues.
We can use java. String unicode to encode a String. We should always utilize this method for overriding init method to avoid any issues as we may forget to add super call in overriding init method with ServletConfig argument. URL Decoding is the reverse process of encoding and we can use java.
What are different methods of session management in servlets? Session is a conversional state between client and server and it can consists of multiple request and response between client and server. String unicode to decode the encoded string. URL Encoding strip the white spaces and replace special characters with escape characters. The best part is that from coding point of view. URL Rewriting E. User Authentication B.
We can use HttpSession for session management in servlets but it works with Cookies and we can disable the cookie in client browser. Cookies are used a lot in web client-server http: Cookies D. Cookies are text data sent by server to the client and it gets saved at the client local machine.
50 Servlet Interview Questions and Answers _ JournalDev.pdf
Servlet API provides cookies support through javax. If we have to make sure an object gets notified when session is destroyed. HttpSessionBindingListener interface. Cookie class that implements Serializable and Cloneable interfaces. HttpServletRequest getCookies method is provided to get the array of Cookies from request.
Java Servlets Interview Questions & Answers
Read more at Cookies in Servlets. Recommended reading Servlet Listener. This interface defines two callback methods — valueBound and valueUnbound that we can define to implement processing logic when the object is added as attribute to the session and when session is destroyed. Similarly HttpServletResponse addCookie Cookie c method is provided to attach cookie in response header.
Authentication and autherization of request for resources. Read more about filters at Servlet Filter. So when we are providing URL rewriting support. Some common tasks that we can do with filters are: Logging request parameters to log files. Servlet Filters are pluggable java components that we can use to intercept and process requests before they are sent to servlets and response after servlet code is finished and before container sends the response back to the client.
Formatting of request body or header before sending it to servlet. Compressing the response data sent to the client. Alter response by adding some cookies. Also if database is down or not configured properly. To handle these scenario. We know that using ServletContext.
If you application has a single entry point user login. We know that servlet filters can be used to intercept request between servlet container and servlet. Read more about different types of listeners and example at Servlet Listener. What if our application is database oriented and we want to set an attribute in ServletContext for Database Connection.
We can configure them in web. If you notice. Servlet API provides support for custom Exception and Error Handler servlets that we can configure in deployment descriptor. Same goes with other error codes like We can provide link to application home page or some details to let user know what went wrong.
Servlet container use this file to configure web application servlets. Since browser understand only HTML. If there are multiple servlets with load-on-startup value such as 0.
We can use load-on-startup element with servlet configuration in web. Usually servlet container loads a servlet on the first client request but sometimes when the servlet is heavy and takes time to loads. With servlet 3. We can use following code snippet to get the actual http: File Upload and Download and common tasks in a java web application.
Integrating Log4j is also very easy in web applications. Please read File Upload Servlet post that provide all the necessary details with example program to upload and download file using servlets.
We can use below code snippet to get the servlet information in a servlet through servlet context object. If you work with database connection a lot in your web application. Servlet 3 introduced use of java annotations to define a servlet.
This helps us in dividing our web http: Servlet Specs 3. WebFilter and WebListener. We can include all the elements of web. Read more about them at Servlet 3 annotations. Web Fragments: Prior to servlet specs 3. So servlet 3 specs introduced web fragments where we can have multiple modules in a single web application.
We can use request. Servlet Annotations: Prior to Servlet 3. This is an advance topic and I recommend to read Async Servlet tutorial. This helps us in building dynamic system where we are loading a component only if we need it.
Servlet Container provides different ways of login based servlet authentication: To http: These methods are addServlet. We can configure our servlet container to use SSL for message communication over the network.
Asynchronous Processing: Asynchronous support was added to delegate the request processing to another thread rather than keeping the servlet thread busy. Form Based Login: A standard HTML form for authentication.
Adding Web Components dynamically: We can use ServletContext object to add servlets. It can increase the throughput performance of the application. Facebook or Twitter. Why not reach little more and connect with me directly on Google Plus.
If you liked these questions. For production environment. I would love to hear your thoughts and opinions on my articles directly. Verisign or Entrust. Please share your thoughts in comments and share your love with sharing on Google Plus. I will keep on adding more servlet based interview questions to the list in future. Recently I started creating video tutorials too. I would like to share it here.
Very nice questions!! I have a questions which I am struggling with. July I love to read the concepts which you have been posted.. Thanks Reply vikas kumar singh says: Plz help me here.. June Very useful. Reply Lukman says: March Thank You Very Much. Reply http: May Thanks a lot!!! Reply Joseph says: April Reply Rieethika says: Reply dakshina gandikota says: January February Can ServletB access its PrintWriter in this case? Reply Benny says: My question is that….
Servlet is singleton by default. January 3. Is servlet singleton by default…? Reply Ramesh says: Reply raam says: Thanks for the same Reply Narendra says: December LoginServlet if you provide again the same configuration for a servlet the container will create another instance of the same servlet.
Reply Hanumant Maindad says: If you define a servlet MyServlet extends HttpServlet. Servlets are not singleton.
LoginServlet Hence Servlets are not singleton. Good for the interviews. Interesting questions. Thanks Reply http: Reply Jaffar Shariff says: November 5. November So can you help understand if the difference you mentioned is correct? Reply guest says: September Reply Naresh says: October 5. Thanks Reply Puneet Kaushik says: Read more about them at Servlet 3 annotations. Web Fragments: Prior to servlet specs 3.
So servlet 3 specs introduced web fragments where we can have multiple modules in a single web application, all these modules should have web-fragment. We can include all the elements of web. This helps us in dividing our web application into separate modules that are included as JAR file in the web application lib directory.
Adding Web Components dynamically: We can use ServletContext object to add servlets, filters and listeners programmatically. This helps us in building dynamic system where we are loading a component only if we need it. These methods are addServlet , addFilter and addListener defined in the servlet context object.
Asynchronous Processing: Asynchronous support was added to delegate the request processing to another thread rather than keeping the servlet thread busy. It can increase the throughput performance of the application. This is an advance topic and I recommend to read Async Servlet tutorial. We can configure our servlet container to use SSL for message communication over the network.
To configure SSL on Tomcat, we need a digital certificate that can be created using Java keytool for development environment.
Servlet Interview Questions and Answers
For production environment, you should get the digital certificate from SSL certificate providers, for example, Verisign or Entrust. Please share your thoughts in comments and share your love with sharing on Google Plus, Facebook or Twitter.
If you have come this far, it means that you liked what you are reading. Why not reach little more and connect with me directly on Facebook or Twitter. I would love to hear your thoughts and opinions on my articles directly. Recently I started creating video tutorials too, so do check out my videos on YouTube. Hi Pankaj, I observed a typo mistake possibly.
HTTP is not a language as you have mentioned. HI can you add the questions on enterprise java bean EJB tutorial and interview questions. Please refer the link: In the answer to question no 19 you wrote that we can have constructor of a Servlet.
But as Servlet is an Interface and we cant have constructor declared for an Interface. So I think answer is incorrect.
Please do correct me if I am wrong. Servlet creation will fail if there is no zero arg constructor available in server.
It is a great post for the freshers and as well as for the experienced. Sir can you please provide me with a pdf file of this. Thanks for spending time for providing this kind of Interview Questions which is helpful for the interview…. The entire material are well organised so that we can have the better understanding about the topics covered… Thank you very much Author…. Very nice questions!! I have a questions which I am struggling with.
I would like to share it here. I think this may clear your doubt…. Per request means when an HTTP request is made, a thread is created or retrieved from a pool to serve it. One thread serves the whole request. Thread per connection would be the same thing except the thread is used for an entire connection, which could be multiple requests and could also have a lot of dead time in between requests.
Servlet containers are thread per request. In your scenario, using a different thread to do work required by a request will, as you expect, allow the response to be sent immediately.
40 TOP SERVLETS INTERVIEW QUESTIONS AND ANSWERS PDF
The thread used to serve that request will also be immediately available for another request, regardless of how long your other thread takes to complete. This is pretty much the way of doing asynchronous work in a thread-per-request servlet container. Hi Pankaj, I love to read the concepts which you have been posted..
Suppose we have two servlets ServletA and Servlet B. Can ServletB access its PrintWriter in this case? Singleton — There should always be only one instance and there should be no way of creating multiple instances of the class by any means. PS- servlet name is myservlet2. Can some one guide how we can look up for the rest of 30 answers? Interesting questions. Good for the interviews. Questions and Answers are quite good, appreciable , but it is only 20 in count i am expecting I am able to see only 20 questions.
I was using google chrome in mobile. Thanks for this good info. Thanks a lot for this as well as other interview questions.
Question collection is very nice and to the point. The questions from 20 are went to hidden, I remembered last time I read all the questions and answers but today when I came here some question went to Hidden display: I found this using my Firebug plugin.
I am only able to see only 20 Servlet Interview Questions and Answers out of Can You please let me know how I can able to see all the answers. Very informative. Best for interview preparation with basics explained very well. Please do continue..
Kindly review answer given for Question No Refer link http: Thanks Braj for pointing out the mistake, I have verified it again and if the load-on-startup is 0 or positive int, then it gets loaded at the time of server startup.
For negative integer, it gets loaded when first client request comes. Corrected the post. Simple,easy to understand,covers most of the things. Excellent guide for interview preparation!! Your email address will not be published. Leave this field empty.
I would love to connect with you personally. You are here: Previous Async Servlet Example. Comments Thank you a lot. This tutorial helps me very very much. Add some more questions like SQL injection and double posting problem. Please fix this. Regards, Diganta. Hi Pankaj, Thanks for such an awesoem Post.
Mostly when we say Servlet, we mean HttpServlet. Answer is also related to HttpServlet only. These quesions are very helpfull to clear the interview. Thank u so much. Hi Pankaj, Very nice questions!! Plz help me here. Useful questions from interview perspective …!!! Thank You Very Much.
The information is very crystal clear and easy to understand. Thanks for the same. Hi Pankaj, My question is that…. Is servlet singleton by default…? LoginServlet if you provide again the same configuration for a servlet the container will create another instance of the same servlet.
PS- servlet name is myservlet2 myservlet2 com. LoginServlet Hence Servlets are not singleton. Thanks, Sanjana. By the way nice article Thanks Mohasin Ali. Really helpful, Covered allmost all topics, easy to revise the subject and face the interviews. I am following you on twitter, but still the answers are locked for me.
How to unlock them? Thank you for your great work. I really excited to read this page. Nice formatting, clear cut answers. The best article i read ever about Servlet , many thanks Pankaj for the useful information. Mohammed Zayadi Huawei Technologies Co. Lots of thanks and blessing from all job seekers…I. Awesome post. Covers all the things that are required for interview..
Hi , Can you please help on the below question answers , 1 what is good logic java or query to find the login user is valid or not, if database has million records?For example, session attributes and static variables can still be accessed by multiple requests on multiple threads at the same time, even when SingleThreadModel servlets are used.
LoginServlet if you provide again the same configuration for a servlet the container will create another instance of the same servlet. Servlet interface.
May It belongs to one application in one JVM. You can easily find answers to these JSP interview question by google but I have included my version for quick reference.
- MUD SWEAT AND TEARS PDF
- WILSON AND WALKER BIOCHEMISTRY EBOOK
- CCNP TSHOOT PORTABLE COMMAND GUIDE PDF
- CTS APTITUDE QUESTIONS AND ANSWERS PDF
- ARM ASSEMBLY LANGUAGE FUNDAMENTALS AND TECHNIQUES EBOOK
- CLOCKWORK PRINCE CASSANDRA CLARE PDF FILE
- GANDHI VADH KYON PDF
- THE TREASURE ISLAND EBOOK
- JSP NOTES PDF
- THE STINKY CHEESE MAN PDF
- NIGHTMARE ABBEY THOMAS LOVE PEACOCK PDF
- AL MATSURAT PDF