Servlet JSP Tutorial

Filed Under: Java EE

Servlet JSP technologies are backbone of Java EE programming. Recently I have written a lot about Servlet and JSP programming and this is a summary post for Servlet JSP Tutorials where I am providing all the article links in the order to read them.

Servlet JSP Tutorial

Servlet JSP Tutorial, JSP Tutorial, JSP Servlet

Java Web Application Tutorial for Beginners

This is the first article in the Java Web Applications tutorial and you will learn about core concepts of web application and how we can use Eclipse to create our first web application. This article provide details about web server, client, HTTP and HTML, URL, Web Container, Web Archive directory structure and Deployment descriptor configurations. This article also includes the “Hello World” servlet example.

Java Servlet Tutorial for Beginners

This tutorial provide details about Servlet and it’s benefits over CGI. The article provide details about Servlet API and it’s main interfaces and classes. We also look into Servlet 3 annotations in brief details that is used in further tutorials. We also learn about servlet attributes and create our Servlet Login Example project.

Servlet Session Management

This article explains about Session and different ways of session management. We learn how we can use Cookies and Servlet API HttpSession interface to maintain user session. We also learn how to use URL rewriting techniques for session management when cookies are disable at client side.

Servlet Filter

Learn about Servlet Filter and how we can use it to intercept request and response objects and manipulate them in between. The article explains about Filter interface, WebFilter annotation, Servlet Filters configuration in web.xml and provide example for logging client requests and session validation with Filters.

Servlet Listener

We explore about Servlet Listener and it’s benefits in this article. We learn about Servlet Listener interface and Event objects and see working example of ServletContextListener, ServletContextAttributeListener, HttpSessionListener and ServletRequestListener with an example program.

Cookies in Servlet

Cookies are used a lot in server client communication. Servlet API HttpSession uses cookie for session management. Here we learn about Servlet Cookie class and how we can use it to add cookies in response and get cookie details from request object with example program.

Servlet Exception Handling

Here we explore about the Exception Handler servlets that we can use to generate custom error message to be sent to client when exception is thrown by Servlet service methods.

Servlet Upload Download File Example

Upload File and Download File scenario is very common in web applications. Here we will learn how we can use Apache Commons FileUpload API to upload file from local system to server and how we can use Servlet for download file and hide the actual file location from the user.

Servlet 3 File Upload using MultipartConfig annotation and Part interface

Servlet 3 specs added support for uploading file without using any third party APIs, this post explains about Servlet API MultipartConfig annotation, Part interface and HttpServletRequest methods that we can use to upload file on server.

Servlet Database Connection and Log4j integration

Most of the web applications connect to database and use log4j for logging purpose. A very detailed post with complete example showing how we can use Listeners and servlet context attributes for Database connection and log4j integration with example project.

Tomcat DataSource JNDI Example

Most of the web application use some relational databases and DataSource is the preferred way to get the database connection. This post will explain you different ways to configure DataSource in Tomcat container and how we can use it in the Servlet based web application.

Servlet Web Application Spring Security Integration

We can use Spring Security module to implement authentication and authorization in our servlet based web application. This tutorial shows you how to do it with a simple example.

Hibernate Servlet DataSource Example

Hibernate is one of the most widely used Java based ORM tool and we can easily integrate it in the servlet based web application. This tutorial provides you basic details about Hibernate and how easily we can integrate it in our web application using Tomcat container JNDI DataSource.

Async Servlet

Servlet 3 introduced asynchronous support in Servlet that is very helpful in getting higher throughput for long running servlets. We can offload the processing to another thread using async servlet, learn async servlet implementation with example program.

Servlet Interview Questions

A collection of 50 servlet interview questions with detailed answers to help you in Java EE interview. It is advisable to go through the tutorial first and then try to answer the questions yourself to check your understanding.

JSP Tutorial

JSP Example Tutorial for Beginners

This is the first post in the JSP series. This post explains about JSP and it’s benefits over servlets, JSP API interfaces, JSP lifecycle phases and methods, JSP comments, JSP scripting elements, scriptlets, JSP expression, JSP directive, JSP declaration, JSP attributes, JSP translation to Servlet with example program. This is a great post to start with if you are new to JSP and want to learn it’s basics.

JSP Implicit Objects

JSP creates 9 objects at the start of service method and we can use them directly in JSP scriptlets, these are called JSP implicit objects. This post provide details about the JSP implicit objects and how we can use them in JSP page with example program.

JSP Directives

JSP directives are used to provide specific instructions to JSP translator when JSP page is translated to Servlet. This post explains about JSP page directive and include directive in detail and their attributes. JSP taglib directive is used for JSTL or custom tags and explained in later tutorials.

JSP Exception Handling

We can create JSP error pages to handle exceptions thrown by application and provide custom response to client. This post explains about the JSP error pages, their configuration in deployment descriptor with example program.

JSP EL Tutorial

JSP Specs 2.0 introduced Expression Language (EL) through which we can get attributes and parameters easily using HTML like tags. This post explains about JSP EL implicit objects, EL operators and their precedence, EL reserve keywords and EL usage with sample program.

JSP Action Tags

JSP provides a bunch of standard action tags that we can use for specific tasks such as working with java bean objects, including other resource, forward the request to other resource etc. This post provide details about all the JSP action elements and show usage of JSP Bean, JSP Forward and JSP include action usage with example program.

JSTL Tutorial

JSP Standard Tag Library (JSTL) is the standard tag library that provides tags to control the JSP page behavior, iteration and control statements, internationalization tags, and SQL tags. This post provide details about the different types of JSTL tags. You will also get details of JSTL Core Tags and their usage with example program.

JSP Custom Tags

Sometimes JSP EL, Action Tags and JSTL are not enough and we may get tempted to write java code in scripting elements. Fortunately JSP is extendable and we can create our own custom tags to be used in JSP pages. This post provide steps to create JSP custom tags and how we can configure and use that in JSP page with example program.

JSP Interview Questions and Answers

This post provides a huge list of JSP interview questions with detailed answers to tackle JSP related interview questions in Java EE interviews. The questions are for beginners as well as experienced programmers, please have a look.

Thats all for Servlet JSP tutorial. I will be adding more tutorials related to some JSP programming scenario. Servlet Security, JSTL tags etc; so make sure you bookmark it for future use.


  1. Z Li says:

    Hello Pankaj,
    Thank you so much for your clear tutorials.
    I really appreciate the effort and time you put in these articles

  2. Palash Gupta says:

    Could I get a pdf of this tutorial?

  3. Tuan says:

    Hi, Please tell me How do you learn Java from beginer to advance?
    I’m newbie.

  4. Pankaj Uprety says:

    sir can u teach me to display stored images in mysql using only jsp

    1. JAAVAR says:

      Hi u don’t need to put your image in your database
      Put him im web content and save just name and url

  5. Nathanael Lima says:

    Hi, Pankaj. I would like to thank you for the great job you did with these tutorials. Seriously, you helped me a lot in so many ways. Please, keep the good work!

  6. Dhiraj says:

    Hi Pankaj ,

    Please add the Webservices(Rest And SOAP) tutorials it would be helpfull for us.

    A lot of thanks for your effort.

  7. Lashya says:

    Hello Pankaj ,
    Can i achieve the operation of sendredirect using forward method of requestdispatcher .

  8. rohit says:

    Sir, can u pls send me the servlet and jsp pdf format ..

  9. Richa Sinha says:

    i want source code of servlet to upload random file(image) to mysql database.
    and source code of servlet to download file from database.
    i have done lots of research.

  10. Bunty says:

    Java Servlet Tutorial
    Java Servlet Tutorial for Beginners
    These links are not working. Showing same page, (
    Please resolve and inform.

    1. Pankaj says:

      I messed up the link while editing few days back, thanks for the comment. I have fixed it.

  11. rizwan says:

    Good collection.
    If you could add tutorials about “integratin of Bootstrap css framework with servlet and jsp”(without using spring). it would be nice. Thanks a lot!

  12. juankyruiz says:

    hello my name is juan o jhon , i will like lear to program in java onli need a manual in spanish pleace can help me ….

    1. abcq says:

      Good explanation of all topics

  13. Sergio Mena says:

    A thoroughly impressive piece of work! I googled up and found these tutorials which are the best I’ve seen so far.

    Thank you very much for your good job.

  14. Kamlakar says:

    Great work! This site has very good content and easy to understand explanation. Keep up the great work!
    If you could add tutorials about Spring framework it would be nice. Thanks a lot!

    1. Pankaj says:

      I am starting Spring Tutorial series in another two weeks i.e from Nov end. 🙂
      I am hoping people would love it.

      1. vikash kumar singh says:

        hello dear friend pankaj ,
        whatever tutorials you provide are good and easy to grasp … i read your tutorial and ebooks which are provided by you… i want to learn spring but it is not avaialble in sequence ….can you send me your spring tutorial in a sequence … thanks

        1. Pankaj says:

          Go to the index post for Spring framework, its there in the order.

  15. sidram says:

    Very Nice explanation..

Comments are closed.

Generic selectors
Exact matches only
Search in title
Search in content