Introduction to JavaServer Pages (JSP)

Fundamentals of JavaServer Pages (JSP): scriptlets, expressions, directives, and building dynamic web pages in Java.

What is JSP ?

JSP- Java Server pages is the technology which helps the user to create static and dynamic web content. Basically a file with .jsp extension.

In a sentence we can say – writing java code inside html file.

How to write java code inside html?

There are three main tag to write java code inside html.

1. Scriptlet tag to execute java code inside html.

Java
<% String msg="Hello world" Out.println(msg); %>

2. Declaration tag to declare global method and global variable

Java
<%! String msg="how are you" %>

3. Expression tag to display java variables

Java
<%= msg %>

Follow the below step to create JSP project.

Step 1

Create a dynamic web project. If you don't know how to create dynamic web project see my post

Step 2

Create .jsp page.

jsp project structure

index.jsp

XML
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"     pageEncoding="ISO-8859-1"%>Insert title here


<%!String msg="Hello World"; %>

<% out.println("From scriptlet   "+msg); %>



<%="From expression   "+msg %>

Examples

download Code

About Glenna Babshire29 Articles
Java & libraries writer. Writes the Java tutorials: the language from Java 21 on, encryption, configuration and the libraries around it.