Monday, October 6, 2025

Top 3 Servlet and JSP Books for Java Developers in 2025 - Best of Lot

I often receive a request from my readers and fellow Java developers about book recommendations to learn Servlet and JSP, two of the key web technology for server-side web development in Java. Unfortunately, there are not many good books to learn Servlet and JSP for Java web developers. Despite being the most popular Java Web technology, there are very few good books to learn Servlet and JSP. The one book which everybody will suggest to you is the Head First Servlet and JSP, which is indeed one of the best books but it's outdated now. It doesn't cover the latest development in Servlet API, particularly Servlet 3.0, and also not been updated for the last 7 to 8 years, but considering others, it is still an excellent book to learn Servlet and JSP.

Wednesday, July 9, 2025

Tomcat – java.lang.OutOfMemoryError: PermGen space Cause and Solution

Tomcat web server often suffers from java.lang.OutOfMemoryError: PermGen space whenever you deploy and un-deploy your web application a couple of times. No matter you are using tomcat6, tomcat7, or using bundled tomcat in Netbeans or Eclipse you will face this error now and then while developing web application on tomcat server. I thought about this article after writing 2 Solution of OutOfMemoryError in Java. I have touched this issue there but then I thought to write a separate tutorial for tomcat outofmemoryerror because I am getting this error too frequently.

Top 10 EJB Interview Question and Answer asked in Java J2EE Interviews

10 EJB Interview Questions and Answer from my collection of interview questions. I have been sharing interview questions on various topics like Singleton interview questions, serialization interview questions, and most recently Spring interview questions. No doubt these questions are very important for performing better in J2EE and EJB interviews but also they open a new path for learning as you may find some concepts new even while revising your knowledge in EJB. EJB interviews have always been tough because its difficult to find people who have hands-on experience on Enterprise Java Beans (EJB) and most of the guys either have worked only on sample projects and are not aware of critical functionalities like distributed transaction management, container-managed persistence, and various other services which EJB provides.

Thursday, June 12, 2025

What is load-on-startup servlet element in web.xml with Example?

load-on-startup is an element that appears inside <servlet> tag in web.xml.4 years back load-on-startup was a very popular servlet interview question because not many Java J2EE developer was familiar with this element and how load-on-startup works inside a servlet container like tomcat or WebSphere. In this J2EE Tutorial, we will see what is a load on startup, how to use the load-on-startup element, and what are different values we can configure for load-On-Startup inside web.xml.

Difference between SendRedirect() and Forward() in JSP Servlet? Example

The difference between SendRedirect and forward is one of the classical interview questions asked during a java web developer interview. This is not just applicable for servlet but also for JSP in which we can use forward action or call sendRedirect() method from scriptlet. Before examining the difference between forward and SendRedirect let’s see what send Redirect method and the forward method does.

SendRedirect ():  

This method is declared in HttpServletResponse Interface.

Signature: void sendRedirect(String url)

Difference between Struts 1 and Struts 2 Web Development Framework

I had worked previously on Struts 1 but never touched Struts 2, especially since Spring MVC was there to take the leading role. Recently one of my friends ask me to help with Struts2, which leads me to look on the Struts2 framework from start. First thing I wanted to find out differences between Struts 1 and Struts 2 framework, because in my experience, if you have worked in the previous version looking differences between two versions of Struts can quickly help to find, what changes and What are the new features, concepts and improvement is offered by Struts 2. Also the difference between Struts 1 and Struts 2 is a good candidate to include in my list of Struts interview questions for quick revision.

Thursday, April 10, 2025

Top 10 Servlet Interview Question Answers for Java JEE Developers

This time its servlet interview questions, I was thinking about what to pick for my interview series and then I thought about J2EE and Servlet is my favorite in that space. Servlet is an important part of any J2EE development and serves as a Controller on many web MVC frameworks and that’s why it’s quite popular on J2EE interviews. These Servlet questions are based on my experience as well as collected by friends and colleague and they are not only good for interview practice but also shows a new direction of learning for anyone who is not very familiar with servlet technology.

Sunday, April 6, 2025

What is GET and POST method in HTTP and HTTPS Protocol? Answer

GET and POST method in HTTP and HTTPS are two most popular methods used to transfer data from client to server using  HTTP (Hyper Text Transfer Protocol)  protocol. Both GET and POST can be used to send requests and receive response but there are significant differences between them. The difference between GET and POST in HTTP or HTTPS is also a popular interview question in JSP and any web programming interview. Since HTML is independent of any web server technology like Java, ASP or PHP and HTTP is core protocol in space of the internet, the importance of a clear understanding of GET and POST method can not be ignored.

5 JSTL Core IF Tag Examples in JSP - Tutorial

<c:if>  or if the tag of JSTL core tag library in JSP is one of the most versatile and useful tags. JSTL if tag allows you  to test for a condition, like checking for a particular parameter in requestScope, sessionScope, or pageScope. You can also check any parameter in request parameters and headers or can check for a variable in JSP page using <c:if> tag. JSTL if tag helps a lot to reduce the amount of Java code from JSP  page and if used, along with expression language JSTL core tag library, can remove almost all Java code from JSP files. Earlier we have seen examples of JSTL foreach tag and JSTL core set tag and this JSP JSTL tutorial is based on if the tag of the JSTL core tag library.

Difference between URL-rewriting URL-encoding in Servlet JSP? Answer

URL-rewriting vs URL-encoding in Servlet JSP
The main difference between URL-rewriting and URL-encoding is that URL-rewriting is a technique to maintain user session if cookies are not enabled on the client browser or browser doesn't support cookie while URL-encoding is a way to pass a string to the server containing special characters by converting special characters like space into some other characters like +. People often confuse between URL encoding and URL rewriting because of there names which sound quite similar for new guys but functionality wise they are totally different to each other, Also servlet encodeURL() method adds more confusion because its sounds like its used for URL Encoding but indeed used for URL Rewriting.

Friday, April 4, 2025

JSTL Set tag examples or <c:set> in JSP – Java J2EE Tutorial

JSTL set tag or <c:set> also called as JSTL Core tag library is a good replacement of <jsp:setProperty> jsp action which lacks lot of functionality and only allow you to set bean property. you can not set Map's key-value or create a scoped variable by using <jsp:setProperty>. jstl <set> tag allows you to do all the stuff related to setting or creating variables or attributes. by using JSTL <c:set> tag you can :

Saturday, May 4, 2024

Top 22 Spring Interview Questions Answers for Java Programmers [UPDATED]

Hey Java Programmers, if you are preparing for a Java developer interview then you should pay special attention to Spring framework-related questions. Spring framework interview questions are on the rise on Java web development and core Java interviews.  This is obvious given Spring Framework is the best most popular framework available for Java application development and now Spring IOC container and Spring MVC framework are used as a de-facto framework for all new Java development. Because of its popularity,  interview questions from the spring framework are top on any list of Java Interview questions and you should also prepare different Spring topics like Spring Boot, Spring Data JPA, Spring Security, Testing and Spring Cloud, etc to do well on Java developer interviews. 

Friday, April 26, 2024

What is bean scope in Spring Framework? Example Tutorial

Java classes or POJO which are managed by Spring Framework are called Bean or Spring Beans and Bean scope in Spring framework or Spring MVC is scope for a bean managed by Spring IOC container. Bean scope refers to the lifecycle and visibility of a bean instance in spring container. The scope determines how long the bean instance will live and how it will be shared with the other parts of application. You may know that Spring is a framework that is based on Dependency Injection and Inversion of Control and provides bean management facilities to Java application. In Spring-managed environment bean (Java Classes) are created and wired by the Spring framework. Spring allows you to define how those beans will be created and the scope of the bean is one of those details. Scope are similar to access modifiers in Java which specifies visibility of a particular class. 

Monday, September 11, 2023

Difference between include directive and include action in JSP Servlet? Example

Difference between include directive and include action is one of the most popular JSP interview questions and also asked as What is the difference between page include and file include in JSP.  Similar to the difference between forward and send redirect and URL encoding vs URL rewriting, this is also asked at a beginner level. Here we will see page include vs file include in detail. Both include directive and include action is used to include the output of a static page e.g. HTML or a dynamic page like jsp inside another jsp file.

Thursday, May 18, 2023

How to fix java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer? [Solution]

The error message clearly says that the Java runtime is not able to find a class called ServletContainer for the Jersey library. This is the Servlet class you have specified in the deployment descriptor of your application. It's similar to DispatcherServlet of Spring MVC and this error is similar to the error you get when DisplayServlet was not in the classpath.
Anyway, java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer comes when you are trying to use Jersey but have not added required dependency on your classpath e.g. those JAR files which contain the class "com.sun.jersey.spi.container.servlet.ServletContainer".

Saturday, May 13, 2023

Difference between Constructor vs Init method in Servlet? Interview Question Answer

Can we have a Constructor in Java Servlet? or Why do we need a constructor in Servlet if there is already an init() method for initializing Servlet, or what is the difference between the init() method and constructor in Servlet are a couple of questions I have seen in various Java web developer interviews. All of these questions are related to the role of the constructor and init() method in the Servlet implementation class. Though I had shared few thoughts on this, when I wrote the top 10 Servlet questions for Java programmers,  I thought to cover it in more detail here.

Wednesday, May 3, 2023

Don't Call System.exit() on Java Web Application in Tomcat - Best Practice

I have recently come across a code snippet, where the programmer was using System.exit() if the application failed to acquire necessary resources after a couple of retries. His reasoning was that the application cannot function if essential resources like the database are not available or there is no disk space to write records in the File system. Ok, I hear you; but System.exit() in Java Web application, which runs inside either web server or application server, which itself is Java program is not a good idea at all. Why? because invoking System.exit() kills your JVM, invoking this from Tomcat or Jetty, will not only kill your application but the most likely server itself. This can be potentially dangerous if that server also hosts other critical applications, which is not uncommon at all.

Sunday, June 26, 2022

How to create Tabs UI using HTML, CSS, jQuery, JSP and JavaScript? Example

JSP is still a popular technology for developing view part of Struts and Spring-based Java applications, but unfortunately, it doesn't have rich UI support available in GWT, or any other library. On another day, we had a requirement to display HTML tables inside tabs, basically, we had two tables of different data set and we need to display them in their own tabs. Users can navigate from one tab to another, and CSS should take care of which tab is currently selected, by highlighting the active tab. Like many Java developers, our hands-on HTML, CSS, and JavaScript are a little bit tight than a web guy, and since our application is not using any UI framework, we had to rely on JSP to do this job.

Tuesday, July 27, 2021

Java PropertyUtils Example - getting and setting properties by name

PropertyUtils class of Apache commons beanutils library is very useful and provides you the ability to modify properties of Java object at runtime. PropertyUtils enables you to write highly configurable code where you can provide the name of bean properties and their values from configuration rather than coding in Java program and Apache PropertyUtils can set those properties on Java object at runtime. One popular example of how powerful PropertyUtils can be is display tag which provides a rich tabular display for JSP pages, it uses PropertyUtils class to get values of an object at runtime and then display it.

Top 10 JSP Interview Questions Answers for Java Programmer

These JSP interview questions and answers are asked in the various J2EE interview and focus on the view part of the MVC framework. JSP or Java Server Pages is a Java technology used to render a dynamic view. Whenever you go for any Java web developer interview there are always some interview questions on JSP. This article is a collection of some JSP interview questions which has asked in the various interview to my friends and colleagues. You can easily find answers to these JSP interview questions by google but I have included my version for quick reference.