Disclosure: This article may contain affiliate links. When you purchase, we may earn a commission.

Top 12 Servlet JSP Interview Questions for Java JEE Developers

Hello guys, Servlets and JSP Interview Questions are the core of any Java JEE Interview and why not they are the back bone of Java Web technology. While the industry have moved from JSP and JSF to React based frontend there are still millions of applications which are using JSP and Servlet in backend. They are also the underlying technology for any web framework on Java like Spring MVC or Spring Boot and It's expected from candidates to have good knowledge of Servlet, JSP, EJB, Struts, or Spring in any JEE interview. That's why Servlets and JSP Interview Questions are very common in any JEE Interviews along with some questions from core Java, Some interview Questions from Spring, and Some EJB interview questions

Since Jakarta EE is the main platform for building enterprise and web applications using the Java programming language, it's important to prepare well for the Java web developer interview, especially If you are in the application development space. 

Servlet and JSP form web layers of Java EE or Jakarta EE framework where Java Server pages are the main view technology and Servlets are the main Controller component of standard MVC architecture.

In this article, we will see a couple of most common or frequently asked JSP and Servlet Interview questions and answers, which can help you with your Java EE interview preparation and understanding some key concepts of Java web applications.




12+ Servlet and JSP Servlet Interview Questions Answers

Here is my list of frequently asked JSP Servlet Interview questions to any Java programmer. Most of these Servlet JSP questions has appeared in various level of J2EE interviews including 2 to 3 and 2 to 4 years experience level. 

None of these questions require special questions and neither of them is a tricky question, they all are focused on fundamentals which are key to clearing any interview.


Question 1: What is JSESSIONID in Java? When does JSESSIONID gets created? (answer)
One of my favorite Servlet JSP Interview questions for 2 to 4 years of experience programmers on web development. The JSESSIONID is a cookie that is used to manage sessions in Java web applications. JSESSIONID is created by Web Container whenever a new session is created.  

You can further see a course like JSP, Servlets, and JDBC for Beginners: Build a Database App to learn more about how JSP and Servlet application works together. 

12+ Servlet and JSP Servlet Interview Questions Answers






Question 2: What is the difference between include action and include directive in JSP? (answer)
Another very popular JSP Interview question mostly asked to 2 to 3 years experienced Java EE programmers. There are a couple of differences, the most important of them is that include action is request time inclusion while include directive is translation time inclusion of another resource like JSP or HTML pages. This question is also asked as the difference between file include and page include. 


Question 3: How do you define the application-wide error page in JSP?
Almost in every Servlet JSP interview, you will see questions from error handling. You can define two kinds of error pages in Java web application, one is using tag <error-page> in web.xml and the other is by using error page JSP which uses the isErrorpage to declare that this jsp page can be used as an error page. 

Other JSP uses that page by using attribute errorpage="error.jsp". Whenever you get an unhandled exception in JSP, the request will be routed to the error page. See How to use the error page in JSP for a detailed answer to this question.



Question 4: Difference between sendRedirect() and forward() in Servlet?
One of the classical Interview Questions from Servlet and JSP. This question is as old as Vector vs ArrayList in core Java. Anyway, see the difference between send redirect and forwarding to answer this Servlet Interview question.


Question 5: How do remove variable using <c:set> tag from JSTL ?
This is one of the tricky Servlet JSP questions. Many people assume that <c:set> can only add or set variables in a particular scope but you can also remove any variable from any scope using JSTL <c:set> tag. See How to use <c:set> JSTL tag in JSP for the exact way to remove any variable from any scope in the JSP page.


Question 6: What is the difference between a Web Server and an Application Server?
This is rather a simple Servlet JSP question to answer. If you have used EJB then you should know that Web Server doesn't contain an EJB container and EJB can not be deployed on that. Application Server is used to deploy and run EJB in a J2EE environment. See 5 differences between Application and Web Server to see more differences.


Servlet and JSP interview questions for Java web developers




Question 7: What is the difference between URL Encoding and URL rewriting?
URL Encoding and URL rewriting is a general web concept irrespective of Java programming language. URL Encoding refers to encoding URL like replacing space with %20, you can see this when the browser sends a request to Server. On the other hand URL Rewriting is a way to manage sessions in web applications. See URL Encoding vs URL Rewriting for more differences.


Question 8: How do you get ServletContext reference inside Servlet?
ServletContext is a very important object in Java Web application. ServletContext object is one per web application and serves as application scope and use to store common config and things which don't change per session. 

It's easy to get the reference of ServletContext in jsp using application implicit variable but Servlet is not available in HttpServletRequest until version 3.0. You need the HttpSession object to retrieve ServletContext in any Servlet. 

A good follow-up question is How do you get ServletContext in Struts Action class or Spring Controller classes. See How to retrieve ServletContext in Servlet, Spring, and Struts for more details.



Question 9: What is the difference between ServletContext and ServletConfig in Java?
One of those classical Servlet Interview Questions which you can't afford to miss. Again ServletContext is used to provide application-wide configure while ServletConfig is used to configure and provide initialization parameters to one Servlet. See ServletContext vs ServletConfig for more differences.




Question 10: Which open source tag library have you used?
This is an interesting Servlet JSP question and gives an opportunity to show how many tag libraries you are familiar with and which ones have you used. Most Java EE programmers answer this question by saying JSTL core tag library, Struts tag library, Spring tag library, or display tag, which is quite a popular tag library to display tabular data and provides a lot of features out-of-the-box, like paging, sorting, and export functionality.



Question 11: What is the difference between the GET and POST methods in the HTTP protocol?
Another classical web interview question, not specific to Servlet or JSP but very important in the context of web development which is based on HTTP protocol. There are several differences between the GET and POST methods including the length of data required to Send to the Server. GET is less secure and can only send limited data hence not useful to transfer sensitive information. See GET vs POST HTTP method for more differences.

Top 12 Servlet JSP Interview Questions for Java JEE Developers



Question 12: What does the load-on-start-up element in web.xml do?
One of the tough Servlet JSP Interview questions especially to 2 years experience guy, who may not be exposed to all tags of web.xml. load-on-startup is related to the loading of Servlet. See What is a load-on-startup tag in web.xml for more details.


These were the list of frequently asked Servlet and JSP Interview questions and answer you can look for quick revision purposes. If you have faced any interesting Servlet JSP questions or if you are looking answer to any Servlet JSP question then please share. They are also good for a telephonic round of Java web developer interviews. 



Other Java Interview Questions articles

Thanks a lot for reading this article so far. If you find these Servlet and JSP Interview questions useful in your preparation for the next Java web developer interview then please share them with your friends and colleagues. 

P. S. - If you are new to Servlet and JSP and looking for a comprehensive course to learn Servlet and JSP then I highly recommend you to join the Full Stack Java developer - Java + JSP + Restful WS + Spring course on Udemy. One of the best courses to learn all essential JAva web technologies and frameworks. 

6 comments:

  1. Great collection of question, useful for both beginners and experience level Java programmer. In fact many of these question I have seen in 2 to 4 years Java and J2EE walk in interviews. Good job and carry on.

    ReplyDelete
  2. i saw other good set of some more questions JSP questions

    ReplyDelete
  3. whai is the use of this section if you are redirecting all the the topics to other blog.......nice collection but waste of time

    ReplyDelete
  4. great compilation....

    ReplyDelete
  5. yes you could have put your own explanations in the same page.

    ReplyDelete
  6. we need indeapth explanation...... minimum 5+ yrs

    ReplyDelete

Feel free to comment, ask questions if you have any doubt.