If you are a B.Tech student like me and learning Java for web development, then at some point you must have heard about JSP. When I first came across it in my 3rd year during Java EE classes, I was honestly confused. I was already struggling with Servlets, JDBC, and suddenly our sir said, “Now we will study JSP.”
Many students get confused here. So in this blog, I’ll explain JSP (Java Server Pages) in very simple words, the way I understood it while preparing for exams and building mini-projects.
Let’s start from the basics.
What is JSP?
JSP (Java Server Pages) is a technology used to create dynamic web pages using Java.
In simple words, JSP allows us to write HTML + Java code together in one file to create dynamic web content.
When I learned this, I realized something important — JSP is mainly used to design the view part of a web application. That means the UI part which users see in their browser.
Example from college project
Suppose you are building a Train Ticket Reservation System (like I did in my mini project).
- You need a login page.
- You need a page to show available trains.
- You need a confirmation page after booking.
If you use only Servlets, you have to write lots of out.println() statements to print HTML. That becomes messy very quickly.
But with JSP, you can directly write HTML and embed Java code wherever needed. That makes life easier.
JSP Architecture
Now let’s understand how JSP actually works internally. This is important for exams and viva.
Many students think JSP directly runs on the browser. But that’s not true.
Step-by-step Working of JSP
- User sends request from browser (for example: login.jsp)
- Request goes to Web Server (like Apache Tomcat)
- JSP file is converted into a Servlet (automatically by server)
- That Servlet is compiled into bytecode
- The compiled class executes and generates HTML
- HTML response is sent back to the browser
Basically:
JSP → Converted to Servlet → Compiled → Executed → Response
When I first understood this, I was like, “Ohhh, so JSP is actually a Servlet behind the scenes!”
Simple Architecture Diagram (Conceptual)
Client (Browser)
↓
Web Server (Tomcat)
↓
JSP → Converted to Servlet
↓
Servlet Executes
↓
HTML Response to Browser
So remember this for exams:
JSP is just a simplified way of writing Servlets.
JSP Tags
Now comes the practical and slightly confusing part JSP tags.
Don’t worry I will explain them simply.
In JSP we use special tags to write Java code inside HTML.
There are mainly three types of JSP tags:
1. Scriptlet Tag
Used to write Java code inside JSP.
Syntax:
<%
// Java code here
%>
Example:
<%
int a = 10;
int b = 20;
out.println(a + b);
%>
When I used scriptlet for the first time, I felt like “Wow, Java inside HTML!” But later I realized we should not overuse it because it makes the code messy.
2. Expression Tag
Used to print values directly to the browser.
Syntax:
<%= expression %>
Example:
<%= "Welcome Ankit" %>
It automatically prints the value.
This is cleaner than using out.println() inside scriptlet.
3. Declaration Tag
Used to declare variables and methods.
Syntax:
<%!
int count = 0;
%>
This declares a variable at class level.
Many students get confused between Scriptlet and Declaration. So remember:
- Scriptlet → inside service method
- Declaration → class level
4. JSP Directives
Directives give instructions to JSP container.
Example:
<%@ page language="java" contentType="text/html" %>
Common directives:
- page
- include
- taglib
5. JSP Action Tags
These are used to perform actions like including files or forwarding requests.
Example:
<jsp:include page="header.jsp" />
Very useful in projects. I used this to include header and footer in multiple pages instead of copying code again and again.
JSP vs Servlet
This is one of the most important comparison questions in exams.
Let’s understand it practically.
When I was building my project, I noticed:
- Servlet is good for processing logic.
- JSP is good for designing UI.
Comparison Table
| Feature | JSP | Servlet |
|---|---|---|
| Code Type | HTML + Java | Only Java |
| Main Use | UI (View) | Business Logic |
| Ease of Writing HTML | Very Easy | Very Difficult (using out.println) |
| Conversion | Converted to Servlet internally | Already a Servlet |
| Development Speed | Faster for UI | Slower for UI |
Real-life Example
Imagine you are preparing for practical exam.
If examiner asks to create a login page:
- With Servlet → You’ll write 50 lines of out.println()
- With JSP → Just write HTML and small Java code
So JSP saves time.
But remember:
In real-world applications, we follow MVC architecture:
- Model → Java classes
- View → JSP
- Controller → Servlet
That is the clean and professional approach.
Advantages of JSP
Now let’s talk about why JSP is useful.
When I shifted from pure Servlet-based UI to JSP, I felt the difference immediately.
- Easy to Write and Read: HTML is written normally. Java code can be inserted wherever needed. It looks cleaner compared to Servlet.
- Separation of Logic and Design:
In good projects:
Servlet handles logic
JSP handles presentation
This makes code maintainable. - Automatic Compilation: JSP is automatically converted into Servlet. We don’t need to compile it manually.
- Reusability with Include
You can reuse header, footer, navbar easily.
Example:
<jsp:include page="navbar.jsp" />
- Very helpful in large projects.
- Faster Development: For college assignments and mini projects, JSP helps a lot. Instead of spending hours writing print statements, you can focus on functionality.
- Built-in Objects :
JSP provides implicit objects like:
- request
- response
- session
- application
- out
These are directly available. No need to create them manually.
When I first saw session object directly available, I thought this is magic. But actually, it’s predefined by JSP container.
When Should You Use JSP?
Now honestly speaking, in modern development many companies use:
- Spring Boot
- React
- Angular
JSP is not very common in new startups. But still:
- Many legacy Java applications use JSP.
- It is very important for understanding Java EE.
- It helps build strong backend fundamentals.
For B.Tech students in India, especially preparing for exams or interviews in service-based companies, JSP knowledge is still useful.
Common Mistakes Beginners Make
I made these mistakes too:
- Writing too much Java code in JSP
- Mixing business logic inside JSP
- Not using MVC pattern
- Not understanding that JSP becomes Servlet internally
Try to avoid these from beginning.
FAQs About JSP
Is JSP front-end or back-end?
JSP runs on server side, so it is back-end technology. But it is mainly used for UI rendering.
Is JSP better than Servlet?
Not exactly. JSP and Servlet serve different purposes. JSP is better for UI, Servlet is better for logic.
Is JSP still used in 2026?
Yes, especially in legacy systems and some enterprise applications. But modern frameworks are more popular.
Can we use JDBC inside JSP?
Technically yes, but not recommended. Better to use Servlet for database logic.
Is JSP difficult to learn?
Not really. If you know:
Basic HTML
Core Java
Servlets
Then JSP is easy to understand.
Conclusion
So finally what is JSP ?
In simple words :
JSP is a server side Java technology which is used to create dynamic web pages easily by combining HTML and Java code.
When I first learned JSP during my B.Tech I was confused. But once I understood that it is just a simplified way of writing Servlet everything became clear.
For beginners and students in India:
- Learn Servlets first
- Then learn JSP
- Understand MVC pattern
- Practice small projects
JSP may not be the hottest technology today but it builds strong fundamentals in Java web development.
And trust me, strong fundamentals matter more than trendy frameworks.
If you are preparing for exams, viva or building your first Java web project JSP is definitely worth learning.
Keep practicing. Keep building small projects. That’s how concepts become clear.
Happy Coding 🙂

