Servlet JSP Tutorial

Published on August 3, 2022


Servlet JSP Tutorial

While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.

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.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors
Default avatar


Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
DigitalOcean Employee
DigitalOcean Employee badge
July 5, 2020

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

- Z Li

    DigitalOcean Employee
    DigitalOcean Employee badge
    December 15, 2019

    Could I get a pdf of this tutorial?

    - Palash Gupta

      DigitalOcean Employee
      DigitalOcean Employee badge
      November 22, 2018

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

      - Tuan

        DigitalOcean Employee
        DigitalOcean Employee badge
        November 16, 2018

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

        - Pankaj Uprety

          DigitalOcean Employee
          DigitalOcean Employee badge
          June 21, 2018

          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!

          - Nathanael Lima

            DigitalOcean Employee
            DigitalOcean Employee badge
            March 27, 2017

            Hi Pankaj , Please add the Webservices(Rest And SOAP) tutorials it would be helpfull for us. A lot of thanks for your effort.

            - Dhiraj

              DigitalOcean Employee
              DigitalOcean Employee badge
              December 26, 2016

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

              - Lashya

                DigitalOcean Employee
                DigitalOcean Employee badge
                December 5, 2016

                Sir, can u pls send me the servlet and jsp pdf format … rohit.mhatre269@gmail.com

                - rohit

                  DigitalOcean Employee
                  DigitalOcean Employee badge
                  July 23, 2016

                  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.

                  - Richa Sinha

                    DigitalOcean Employee
                    DigitalOcean Employee badge
                    July 2, 2016

                    Java Servlet Tutorial Java Servlet Tutorial for Beginners These links are not working. Showing same page, (https://www.journaldev.com/2114/servlet-jsp-tutorial) Please resolve and inform.

                    - Bunty

                      Try DigitalOcean for free

                      Click below to sign up and get $200 of credit to try our products over 60 days!

                      Sign up

                      Join the Tech Talk
                      Success! Thank you! Please check your email for further details.

                      Please complete your information!

                      Featured on Community

                      Get our biweekly newsletter

                      Sign up for Infrastructure as a Newsletter.

                      Hollie's Hub for Good

                      Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

                      Become a contributor

                      Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

                      Welcome to the developer cloud

                      DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

                      Learn more
                      DigitalOcean Cloud Control Panel