JSP (JavaServer Pages) is a server-side web technology used to create dynamic web pages using Java.
👉 It allows embedding Java code inside HTML.
👉 Draw this in exam:
Browser → Request → Web Server → JSP File
↓
Converted to Servlet
↓
Executed (Java)
↓
HTML Response → Browser
✔ JSP is converted into a Servlet before execution.
<%@ page language="java" %>
<html>
<body>
<%
out.println("Hello World");
%>
</body>
</html>
<% %> → Java codeout.println() → prints outputUsed to write Java code.
<%
int x = 10;
%>
Used to display values.
<%= x %>
Used to declare variables/methods.
<%! int y = 5; %>
Provides instructions to JSP engine.
<%@ page import="java.util.*" %>
JSP provides built-in objects:
requestresponseoutsessionapplication<%
String name = request.getParameter("name");
out.println(name);
%>
<%
if (x > 5) {
out.println("Greater");
}
%>
<form action="test.jsp">
Name: <input type="text" name="name">
<input type="submit">
</form>
<%
String name = request.getParameter("name");
out.println("Hello " + name);
%>
<%
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/test","root","");
%>
<%
session.setAttribute("user", "Ali");
%>
👉 Diagram for exam:
1. Translation (JSP → Servlet)
2. Compilation
3. Initialization
4. Execution
5. Destruction
✔ JSP runs on server-side
✔ File extension is .jsp
✔ Converted into Servlet
✔ Uses Java language
✔ Avoid too much Java code in JSP (use MVC)
| Feature | JSP | PHP |
|---|---|---|
| Language | Java | PHP |
| Platform | Platform-independent | Platform-independent |
| Performance | Faster | Moderate |
| Complexity | High | Easy |
JSP = Java-based server-side technology
Converts into Servlet before execution
Key concepts:
👉 Used to build dynamic, enterprise-level web applications.
Open this section to load past papers