“What is Java Server Page (JSP) technology? Why do we need JSP technology if we already have Servlets?
” These features reduce the amount of Java code required.
Java Server Page (JSP) Technology – Long Answer (15 Marks)
Java Server Pages (JSP) is a server-side web technology used to create dynamic, platform-independent webpages. It 5. Better Support for Web Designers
is a part of the Java EE (Enterprise Edition) framework and is mainly used to build web applications where the Web design teams prefer working with HTML. JSP allows them to design pages in the traditional HTML format and
content of the webpage changes according to the user’s request, database values, session information, etc. JSP then insert dynamic elements wherever needed. Servlets do not support this flexibility.
allows developers to embed Java code directly inside HTML pages using special JSP tags. Because of this, it becomes
very easy to create webpages that combine presentation (HTML) with server-side logic. 6. Faster Development of Dynamic Webpages
JSP pages are saved with a “.jsp” extension and are executed on a web server such as Tomcat. When a JSP page is Since JSP pages are easier to write and update, they speed up the development process. In large projects where
requested for the first time, the server automatically converts the JSP file into a Servlet, compiles it, and then many UI pages are required, JSP significantly reduces development time compared to Servlets.
executes it. Thus, technically a JSP is also a Servlet, but it is a more convenient and user-friendly way of writing
server-side code for web applications. 7. Reusability and Component-Based Development
JSP supports reusable components like:
Why JSP is Needed When We Already Have Servlets? • Include directives
Although Servlets were the first server-side technology in Java, they had a major limitation: • Tag files
Servlets mix HTML code and Java code together in a tedious way. • Custom tags
Because of this, writing large webpages using Servlets becomes very difficult. These allow shared components across multiple webpages. Servlets do not support this kind of page-level reuse
JSP was introduced to overcome the drawbacks of Servlets and to simplify the creation of dynamic websites. easily.
ADVANTAGES/FEATURES OF JSP Conclusion
Java Server Pages (JSP) is a powerful technology used to build dynamic and interactive webpages in Java. While
1. JSP Separates Presentation and Business Logic
Servlets remain important for handling business logic and controlling the flow of the application, JSP offers a much
Servlets are written entirely in Java. So if we want to generate HTML output, we must write statements like:
easier, clean, and designer-friendly way of generating HTML output. JSP overcomes the limitations of Servlets by
[Link]("<html>");
separating presentation from logic, supporting tag libraries, providing implicit objects, and simplifying code writing.
[Link]("<body>");
Therefore, both Servlets and JSP work together, but JSP is preferred for creating the user interface of web
This becomes messy and difficult to maintain.
applications.
In JSP, HTML can be written normally, and only small parts require Java code. This makes JSP much more suitable for
designers who work with UI. JSP supports MVC architecture where:
• JSP acts as View (presentation) “What is Java Server Page Action? Why do we need JSP technology if we already have Servlets?”
• Servlet acts as Controller (business logic)
Java Server Page (JSP) Action – Long Answer (15 Marks)
2. Easier to Write and Maintain Java Server Pages (JSP) is a server-side web technology used to create dynamic webpages using Java. JSP provides
JSP allows developers to write: many useful features to make webpage development easy, and one of the most important features is JSP Action
• HTML Tags. These action tags allow the programmer to control the behaviour of the JSP engine, perform dynamic tasks,
• CSS interact with JavaBeans, forward requests to other resources, include output from other pages, and create reusable
• JavaScript components.
• Java code using JSP tags
Because the structure is cleaner, debugging and updating pages becomes easier. In Servlets, even small design Meaning of JSP Action
changes require rewriting Java code. JSP avoids this problem. JSP Actions are special XML-based tags that perform predefined tasks at runtime. These tags are processed by the
JSP engine while the page is being executed. Action tags always start with the prefix:
3. Automatic Page Compilation <jsp:actionName ... />
When a JSP page is executed for the first time, the server automatically: They are used for tasks such as:
1. Converts the JSP code into a Servlet • Forwarding the request to another page
2. Compiles the Servlet • Including another page’s output
3. Runs it • Creating or accessing JavaBean objects
This reduces the workload of the programmer. In Servlets, the programmer must manually write, compile, and • Transferring properties between components
deploy each change. • Dynamically inserting content at request time
Action tags make JSP more powerful and reduce the amount of Java code inside the page.
4. Built-in Tag Libraries and JSP Features
JSP provides many built-in features that Servlets do not offer, such as: Types of JSP Action Tags
• JSP Expression Language (EL) for accessing data easily 1. jsp:useBean – Used to create or locate a JavaBean object.
• JSTL (JSP Standard Tag Library) for looping, conditional statements, database access 2. jsp:setProperty – Used to set values in a JavaBean.
• Custom tags for reusable components 3. jsp:getProperty – Used to read values from a JavaBean.
• Implicit objects such as request, session, application, out, config, etc. 4. jsp:include – Includes another resource at request time.
5. jsp:forward – Forwards the request to another resource (JSP/Servlet/HTML).
6. jsp:param – Used to pass parameters to other resources. 2. JSP STANDARD TAG LIBRARY (JSTL)
7. jsp:plugin – Used to embed Java applets or plugins in the webpage. JSTL is a predefined, ready-made tag library provided by Java for performing common tasks in JSP.
These tags bring a modular, reusable, and cleaner structure to JSP pages. Instead of writing custom code, developers can directly use JSTL tags to perform:
• Conditional checks
JSP Session • Looping
In web applications, the HTTP protocol used by browsers is stateless, which means it does not remember any • Database operations
information about a user once the request is completed. To build real-world applications like login systems, shopping • Formatting
carts, banking apps, or personalised webpages, the server must remember the user’s data across multiple requests. • Internationalization
This memory of user information during the entire visit is called a session. • URL management
In JSP (Java Server Pages), session management is provided automatically through the HttpSession object, which JSTL tags belong to categories like:
helps store and retrieve user-specific information until the user logs out, the session expires, or the browser is closed. a) Core Tags
For loops, conditions, URL handling, variable setting
Meaning of JSP Session Examples:
A JSP Session is a server-side mechanism used to store information about a single user and make it available across <c:if test="">
multiple pages of the website. Each user who accesses the website gets a unique session ID, and all their personal <c:forEach>
data is connected to this ID. JSP internally uses HttpSession from Servlet API for this purpose. b) SQL Tags
For database queries
Custom Tag Libraries and JSP Standard Tag Libraries – Meaning & Importance (LONG ANSWER) <sql:query>
<sql:update>
In JSP, tags play a very important role in reducing Java code and making webpages cleaner, more readable, and easier c) Formatting Tags
to maintain. Apart from the basic JSP tags, two major types of tag libraries are used in real applications: For currency, date, number formatting
1. Custom Tag Libraries <fmt:formatNumber>
2. JSP Standard Tag Library (JSTL) <fmt:formatDate>
Both serve the purpose of reusability, reducing Java code, and promoting cleaner MVC design. d) XML Tags
For XML data manipulation
1. CUSTOM TAG LIBRARIES (Meaning) <x:parse>
A Custom Tag Library is a collection of user-defined tags created by developers to perform specific tasks inside a JSP
page. Importance of Custom Tags and JSTL
Whenever a developer feels that some code is repeated many times across pages (like formatting dates, validating Both custom tag libraries and JSTL play a major role in simplifying JSP programming.
input, printing common layout, etc.), they can create their own tag to perform that task.
Custom tags look exactly like HTML/XML tags: 1. Reduce Java Code in JSP Pages
<mytags:formatDate value="2025-01-01"/> They remove the need for writing Java scriptlets (<% %>), making pages cleaner and easier to debug.
These tags hide Java code inside reusable components, allowing designers and developers to work easily without
repeating logic. 2. Reusability
Tags can be used again and again across multiple JSP pages.
Purpose / Why Custom Tags Are Needed? This avoids duplication and improves consistency.
• To re-use common Java code across many JSP pages
• To reduce scriptlets (<% Java code %>) in JSP 3. Easy for Designers
• To separate business logic from presentation HTML designers can use tags without knowing Java.
• To allow non-programmers (UI designers) to use complex functionality easily They just write XML-style tags, and the logic runs invisibly.
• To create clean and well-structured JSP pages
Custom tags are written once and then used anywhere in the project. 4. Faster Development
Complex tasks like looping, validation, formatting, querying a database, and manipulating data become extremely
Features of Custom Tags simple.
• Encapsulate Java logic inside reusable components
• XML-based, easy to understand 5. Better Separation of Concerns
• Support attributes (like HTML tags) Tags keep logic separate from presentation, supporting MVC architecture:
• Allow looping, condition checking, formatting, etc. • JSP = View
• Improve maintainability of large applications • Servlet/Java classes = Controller
• Tags = reusable components
6. Improves Maintainability
Since tags hide Java code, any change needed in logic is done in one place only—inside the tag class. • It is very easy to read
There is no need to modify 10–20 JSP pages. • It separates logic from presentation
• It is useful in MVC-based web applications
7. Cleaner and Professional JSP Structure • It accesses data without scriptlets
Pages look like HTML mixed with XML tags → more readable and professional. Example idea: printing username directly without Java code.
Conclusion 4. Standard Action Tags
Custom Tag Libraries and the JSP Standard Tag Library (JSTL) are powerful features of JSP that help developers write Standard action tags are predefined tags provided by JSP to perform tasks while the page is running.
clean, modular, and reusable web pages. Custom tags allow developers to create their own reusable components, They look like XML tags and make the page more organized.
while JSTL provides a rich set of ready-made tags for common tasks such as looping, formatting, database access, and Action tags are used for:
conditional processing. Their importance lies in reducing code complexity, improving maintainability, encouraging • including other pages dynamically
separation of logic and presentation, and speeding up web application development. • forwarding user requests
• setting or getting bean properties
JSP Elements – Long, Clean, and Exam-Focused Answer • passing parameters
A JSP (Java Server Page) contains different elements that help in mixing HTML with dynamic Java-based content. • controlling flow between components
These elements control how the page behaves, how Java interacts with HTML, and how the page communicates with They reduce Java code and help maintain a cleaner structure.
the server.
All JSP pages are built using the following major elements: 5. Tag Libraries (JSTL + Custom Tags)
Tag libraries extend JSP by providing additional, reusable components.
1. Directive Elements There are two main tag libraries:
Directive elements act like instructions for the JSP engine. a) JSTL (JSP Standard Tag Library)
They tell the server how the page should be processed when it is converted into a servlet. A powerful set of ready-made tags used for looping, conditions, formatting, internationalization, and basic database
There are three directive elements: actions.
a) Page Directive It reduces scriptlets and makes the page more readable.
This directive defines general settings for the page. b) Custom Tag Libraries
It can specify which classes to import, what content type the page should send, how errors should be handled, These are tags created by developers to perform repeated tasks.
buffering settings, etc. They hide complex Java code behind simple tags and help in reusability, maintainability, and clear design.
It basically controls the overall behavior of the page.
b) Include Directive JSTL – JSP Standard Tag Library (Easy Explanation)
This directive inserts another file (such as a header, footer, or menu) into the JSP before the page is compiled. JSTL (JavaServer Pages Standard Tag Library) is a collection of ready-made tags provided by Java to make JSP pages
It improves reusability and keeps the page structure clean by avoiding repetition. easier to write, more readable, and more powerful.
c) Taglib Directive Instead of writing Java code inside JSP pages, JSTL allows developers to use simple XML-style tags to perform
This directive is used when a page wants to use an external tag library such as JSTL or custom tags. common tasks.
It gives access to a group of powerful predefined tags. In simple words:
JSTL is a set of predefined tags that replace Java code in JSP pages.
2. Scripting Elements
These elements allow Java code to be used inside the JSP page. Why JSTL is Used?
They help in adding dynamic behavior and performing tasks that require logic. JSTL is used because:
There are three scripting elements: • It reduces or eliminates Java scriptlets (<% %>) from JSP pages.
a) Declaration Element • It makes the JSP page cleaner, simple, and easier to maintain.
Used to declare variables or methods that can be used throughout the JSP page. • It supports common operations like looping, conditions, formatting, and database access.
The declared items become part of the servlet class created from the JSP. • It helps in building MVC-based applications where JSP is only for presentation.
b) Scriptlet Element Importance of JSTL
Used to write Java statements inside the page. • Makes JSP pages more readable and professional.
Although older JSP pages used many scriptlets, modern practice discourages them because they mix Java with HTML. • Promotes code reusability and cleaner UI design.
c) Expression Element • Helps separate business logic from presentation.
Used to display a value directly on the webpage without writing long Java code. • Reduces the need for Java inside HTML.
It is mainly for showing dynamic output. • Provides standard and consistent behavior across JSP pages.
3. Expression Language (EL)
Expression Language is a simple and powerful way to access values stored in request, session, or application objects.
It removes the need to write Java code and makes the page cleaner.
EL is widely used because: