Updates
  • Starting New Weekday Batch for Full Stack Java Development on 27 September 2025 @ 03:00 PM to 06:00 PM
  • Starting New Weekday Batch for MERN Stack Development on 29 September 2025 @ 04:00 PM to 06:00 PM

Introduction to JSP

• JSP stands for Java Server Page.
• JSP is a combination of HTML tags and Java code.
• JSP will be processed by the web container by creating a Servlet class for it.
• JSP will be used to design a dynamic response for the client.
• The extension for the file must be .jsp.
• You can access some predefined web component objects:

o HttpServletRequeest request
o HttpSession session
o Writer out
o ServletContext application etc.

• You need to use some scripting elements to write the Java code.

1. To write the statements that are valid in any method.
 <%
  //java Implementation valid inside a method
  %>
Note: you must define ; (semi colon) at last.
2. To write the data in the response stream
 <%
  =<varName>
  %>
Note: you must define ; (semi colon) at last.
3. To import the package in jsp
 <%
  @page import=”java.util.*”
  %>
 <%
  %@page import=”javau.io.*”%
  %>

File Required For Program

1. Index.jsp

1. Index.jsp

            
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO8859-1">
      <title>Insert title here</title>
   </head>
   <body>
      <h1>THIS IS INDEX JSP</h1>
      <%
         for(int i=0;i<5;i++){
         System.out.println(i);
         out.write("<br>"+i);
         }
         %>
      <br>
      Current Time
      <%
         Date dt=new Date();
         out.write("<br>"+dt);
         String str="JTC";
         %>
      <br>
      <font color="red" size="5"><%=dt %></font>
      <br>
      <font color="red" size="5"><%=str %></font>
   </body>
</html>
        
            

Files Required for Program

1. Index.jsp
2. Show.jsp

1. Index.jsp

            
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
      <title>Insert title here</title>
   </head>
   <body>
      <h1>THIS IS INDEX JSP</h1>
      <%
         String str="jtc";
         application.setAttribute("MSG",str);
         application.setAttribute("MSG","JTC");
         List<String> emails=new ArrayList<String>();
         emails.add("som@jtc.com");
         emails.add("Rahul@jtc.com");
         emails.add("Neha@jtc.com");
         emails.add("Rahul@jtc.com");
         application.setAttribute("EMAILS",emails);
         %>
      <a href="show.jsp">Show Data</a>
   </body>
</html>
        
            

2. show.jsp

            
<%@page import="java.util.List"%>
<%@ page language="java"contentType="text/html; charset=ISO-8859-1"pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
   <head>
      <meta http-equiv="Content-Type"
         content="text/html; charset=ISO-8859-1">
      <title>Insert title here</title>
   </head>
   <body>
      <h1>THIS IS SHOW JSP</h1>
      <%=application.getAttribute("MSG") %>
      <br>
      <%
         Object obj=application.getAttribute("EMAILS");
         List<String> values=(List<String>)obj;
         for(String eml:values){
         %>
      <font color="red"><br><%=eml %></font>
      <%
         }
         %>
   </body>
</html>