SlideShare a Scribd company logo
1 of 27
JSP and JSTL
Introduction to JSP
 It stands for Java Server Pages.
 It is a server side technology.
 It is used for creating web application.
 It is used to create dynamic web content.
 In this JSP tags are used to insert JAVA code into
HTML pages.
 It is an advanced version of Servlet Technology.
 It is a Web based technology helps us to create
dynamic and platform independent web pages.
 In this, Java code can be inserted in HTML/ XML
pages or both.
 JSP is first converted into servlet by JSP container
before processing the client’s request.
JSP pages are more advantageous
than Servlet:
 They are easy to maintain.
 No recompilation or redeployment is required.
 JSP has access to entire API of JAVA .
 JSP are extended version of Servlet
Features of JSP
 Coding in JSP is easy :- As it is just adding JAVA code to
HTML/XML.
 Reduction in the length of Code :- In JSP we use action
tags, custom tags etc.
 Connection to Database is easier :-It is easier to connect
website to database and allows to read or write data easily
to the database.
 Make Interactive websites :- In this we can create
dynamic web pages which helps user to interact in real
time environment.
 Portable, Powerful, flexible and easy to maintain :- as
these are browser and server independent.
 No Redeployment and No Re-Compilation :- It is
dynamic, secure and platform independent so no need to
re-compilation.
 Extension to Servlet :- as it has all features of servlets,
implicit objects and custom tags
syntax
 Declaration Tag :-It is used to declare variables.
Syntax:- <%! Dec var %>
Example:- <%! int var=10; %>
Syntax:- <%= expression %>
Example:- <% num1 = num1+num2 %>
Syntax:- <% -- JSP Comments %>
How to run JSP in Eclipse IDE
using Apache Tomcat Server
Step 1: In order to run JSP in Eclipse IDE, you need to
have Apache tomcat Server configured in Eclipse
IDE.
Create dynamic web project
Give a Project name and click Finish.
Create a JSP file. Right click on the
WebContent-> New -> Click on JSP File
Enter file name and click Finish.
Write some JSP codeRun the JSP project. Right
click on your JSP project -> Run as -> Click on
“Run on Server”.
Select the Server and click next.
Select the Server and click next.
Click on Add All -> Click Finish
JSP - Standard Tag Library
 The JavaServer Pages Standard Tag Library (JSTL) is a
collection of useful JSP tags which encapsulates the core
functionality common to many JSP applications.
 JSTL has support for common, structural tasks such as
iteration and conditionals, tags for manipulating XML
documents, internationalization tags, and SQL tags. It
also provides a framework for integrating the existing
custom tags with the JSTL tags.
Advantage of JSTL
 Fast Development JSTL provides many tags that
simplify the JSP.
 Code Reusability We can use the JSTL tags on
various pages.
 No need to use scriptlet tag It avoids the use of
scriptlet tag.
Install JSTL Library
To begin working with JSP tages you need to first install the JSTL
library. If you are using the Apache Tomcat container, then
follow these two steps −
Step 1 − Download the binary distribution from Apache Standard
Taglib and unpack the compressed file.
Step 2 − To use the Standard Taglib from its Jakarta Taglibs
distribution, simply copy the JAR files in the distribution's 'lib'
directory to your application's webappsROOTWEB-
INFlib directory.
To use any of the libraries, you must include a <taglib> directive
at the top of each JSP that uses the library.
Classification of The JSTL
Tags
The JSTL tags can be classified, according to their
functions, into the following JSTL tag library groups that
can be used when creating a JSP page −
 Core Tags
 Formatting tags
 SQL tags
 XML tags
 JSTL Functions
Core Tags
S.No. Tag & Description
1 <c:out>Like <%= ... >, but for expressions.
2 <c:set >Sets the result of an expression evaluation in a 'scope'
3
<c:remove >Removes a scoped variable (from a particular scope, if specified).
4
<c:catch>Catches any Throwable that occurs in its body and optionally exposes it.
5
<c:if>Simple conditional tag which evalutes its body if the supplied condition is true.
6
<c:choose>Simple conditional tag that establishes a context for mutually exclusive conditional operations, marked
by <when> and <otherwise>.
7
<c:when>Subtag of <choose> that includes its body if its condition evalutes to 'true'.
8
<c:otherwise >Subtag of <choose> that follows the <when> tags and runs only if all of the prior conditions evaluated
to 'false'.
9
<c:import>Retrieves an absolute or relative URL and exposes its contents to either the page, a String in 'var', or a
Reader in 'varReader'.
10
<c:forEach >The basic iteration tag, accepting many different collection types and supporting subsetting and other
functionality .
11
<c:forTokens>Iterates over tokens, separated by the supplied delimeters.
12 <c:param>Adds a parameter to a containing 'import' tag's URL.
13 <c:redirect >Redirects to a new URL.
14 <c:url>Creates a URL with optional query parameters
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>Tag Example</title>
</head>
<body>
<c:out value="${'Welcome to JSTL'}"/>
</body>
</html>
Java Servlet and JDBC Example | Insert data in
MySQL
to start with interfacing Java Servlet Program with
JDBC Connection:
 Proper JDBC Environment should set-up along with
database creation.
 To do so, download the mysql-connector.jar file from
the internet,
 As it is downloaded, move the jar file to the apache-
tomcat server folder,
 Place the file in lib folder present in the apache-
tomcat directory.
 To start with the basic concept of interfacing:
 Step 1: Creation of Database and Table in MySQL
Step 2: Implementation of required
Web-pages
<html>
<head>
<title>Insert Data</title>
</head>
<body>
<form action="./InsertData" method="post">
<p>ID:</p>
<input type="text" name="id"/>
<br/>
<p>String:</p>
<input type="text" name="string"/>
<br/><br/><br/>
<input type="submit"/>
</form>
</body>
</html>
Step 3: Creation of Java Servlet program with JDBC
Connection
to create a JDBC Connection steps are
1. Import all the packages
2. Register the JDBC Driver
3. Open a connection
4. Execute the query, and retrieve the result
5. Clean up the JDBC Environment
6. Create a separate class to create a connection of
database, as it is a lame process to writing the
same code snippet in all the program. Create a
.java file which returns a Connection object.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
// This class can be used to initialize the database connection
public class DatabaseConnection {
protected static Connection initializeDatabase()
throws SQLException, ClassNotFoundException
{
// Initialize all the information regarding
// Database Connection
String dbDriver = "com.mysql.jdbc.Driver";
String dbURL = "jdbc:mysql:// localhost:3306/";
// Database name to access
String dbName = "demoprj";
String dbUsername = "root";
String dbPassword = "root";
Class.forName(dbDriver);
Connection con = DriverManager.getConnection(dbURL + dbName,
dbUsername,
dbPassword);
return con;
}
}
To use this class method, create an object in Java Servlet programBelow
program shows Servlet Class which create a connection and insert the data in
the demo table,
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import javax.servlet.ServletException;
import
javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import
javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse
;
// Import Database Connection Class
file
import code.DatabaseConnection;
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
try {
// Initialize the database
Connection con = DatabaseConnection.initializeDatabase();
// Create a SQL query to insert data into demo table
// demo table consists of two columns, so two '?' is used
PreparedStatement st = con
.prepareStatement("insert into demo values(?, ?)");
// For the first parameter,
// get the data using request object
// sets the data to st pointer
st.setInt(1, Integer.valueOf(request.getParameter("id")));
// Same for second parameter
st.setString(2, request.getParameter("string"));
// Execute the insert command using executeUpdate()
// to make changes in database
st.executeUpdate();
// Close all the connections
st.close();
con.close();
// Get a writer pointer
// to display the successful result
PrintWriter out = response.getWriter();
out.println("<html><body><b>Successfully Inserted"
+ "</b></body></html>");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
step 5: Get the data from the HTML fileTo get the
data from the HTML file, the request object is used
which calls getParameter() Method to fetch the data
from the channel. After successful insertion, the
writer object is created to display a success
message.
 After insertion operation from Servlet, data will be
reflected in MySQL Database

More Related Content

What's hot

What's hot (20)

JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Jsp element
Jsp elementJsp element
Jsp element
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
DataBase Connectivity
DataBase ConnectivityDataBase Connectivity
DataBase Connectivity
 
Jsp
JspJsp
Jsp
 
Jdbc example program with access and MySql
Jdbc example program with access and MySqlJdbc example program with access and MySql
Jdbc example program with access and MySql
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
 
Java Servlets & JSP
Java Servlets & JSPJava Servlets & JSP
Java Servlets & JSP
 
Jsp chapter 1
Jsp chapter 1Jsp chapter 1
Jsp chapter 1
 
JDBC in Servlets
JDBC in ServletsJDBC in Servlets
JDBC in Servlets
 
Introduction to JSP
Introduction to JSPIntroduction to JSP
Introduction to JSP
 
Servlet and jsp interview questions
Servlet and jsp interview questionsServlet and jsp interview questions
Servlet and jsp interview questions
 
JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGES
 
Web Applications and Deployment
Web Applications and DeploymentWeb Applications and Deployment
Web Applications and Deployment
 
JSP Directives
JSP DirectivesJSP Directives
JSP Directives
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
 
Database connect
Database connectDatabase connect
Database connect
 
Jsp Introduction Tutorial
Jsp Introduction TutorialJsp Introduction Tutorial
Jsp Introduction Tutorial
 
JDBC
JDBCJDBC
JDBC
 

Similar to Jsp and jstl (20)

Jsp tutorial
Jsp tutorialJsp tutorial
Jsp tutorial
 
Jdbc
JdbcJdbc
Jdbc
 
Jsp in Servlet by Rj
Jsp in Servlet by RjJsp in Servlet by Rj
Jsp in Servlet by Rj
 
Jsp and Servlets
Jsp and ServletsJsp and Servlets
Jsp and Servlets
 
Unit 4 web technology uptu
Unit 4 web technology uptuUnit 4 web technology uptu
Unit 4 web technology uptu
 
Unit 4 1 web technology uptu
Unit 4 1 web technology uptuUnit 4 1 web technology uptu
Unit 4 1 web technology uptu
 
J2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsJ2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - Components
 
Cis 274 intro
Cis 274   introCis 274   intro
Cis 274 intro
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
 
Tomcat + other things
Tomcat + other thingsTomcat + other things
Tomcat + other things
 
Ta Javaserverside Eran Toch
Ta Javaserverside Eran TochTa Javaserverside Eran Toch
Ta Javaserverside Eran Toch
 
JSP.pptx
JSP.pptxJSP.pptx
JSP.pptx
 
Web container and Apache Tomcat
Web container and Apache TomcatWeb container and Apache Tomcat
Web container and Apache Tomcat
 
Bt0083 server side programing 2
Bt0083 server side programing  2Bt0083 server side programing  2
Bt0083 server side programing 2
 
Arpita industrial trainingppt
Arpita industrial trainingpptArpita industrial trainingppt
Arpita industrial trainingppt
 
JSP overview
JSP overviewJSP overview
JSP overview
 
C:\fakepath\jsp01
C:\fakepath\jsp01C:\fakepath\jsp01
C:\fakepath\jsp01
 
JEE5 New Features
JEE5 New FeaturesJEE5 New Features
JEE5 New Features
 
J2EE jsp_01
J2EE jsp_01J2EE jsp_01
J2EE jsp_01
 
Jsp standard tag_library
Jsp standard tag_libraryJsp standard tag_library
Jsp standard tag_library
 

More from vishal choudhary (20)

SE-Lecture1.ppt
SE-Lecture1.pptSE-Lecture1.ppt
SE-Lecture1.ppt
 
SE-Testing.ppt
SE-Testing.pptSE-Testing.ppt
SE-Testing.ppt
 
SE-CyclomaticComplexityand Testing.ppt
SE-CyclomaticComplexityand Testing.pptSE-CyclomaticComplexityand Testing.ppt
SE-CyclomaticComplexityand Testing.ppt
 
SE-Lecture-7.pptx
SE-Lecture-7.pptxSE-Lecture-7.pptx
SE-Lecture-7.pptx
 
Se-Lecture-6.ppt
Se-Lecture-6.pptSe-Lecture-6.ppt
Se-Lecture-6.ppt
 
SE-Lecture-5.pptx
SE-Lecture-5.pptxSE-Lecture-5.pptx
SE-Lecture-5.pptx
 
XML.pptx
XML.pptxXML.pptx
XML.pptx
 
SE-Lecture-8.pptx
SE-Lecture-8.pptxSE-Lecture-8.pptx
SE-Lecture-8.pptx
 
SE-coupling and cohesion.ppt
SE-coupling and cohesion.pptSE-coupling and cohesion.ppt
SE-coupling and cohesion.ppt
 
SE-Lecture-2.pptx
SE-Lecture-2.pptxSE-Lecture-2.pptx
SE-Lecture-2.pptx
 
SE-software design.ppt
SE-software design.pptSE-software design.ppt
SE-software design.ppt
 
SE1.ppt
SE1.pptSE1.ppt
SE1.ppt
 
SE-Lecture-4.pptx
SE-Lecture-4.pptxSE-Lecture-4.pptx
SE-Lecture-4.pptx
 
SE-Lecture=3.pptx
SE-Lecture=3.pptxSE-Lecture=3.pptx
SE-Lecture=3.pptx
 
Multimedia-Lecture-Animation.pptx
Multimedia-Lecture-Animation.pptxMultimedia-Lecture-Animation.pptx
Multimedia-Lecture-Animation.pptx
 
MultimediaLecture5.pptx
MultimediaLecture5.pptxMultimediaLecture5.pptx
MultimediaLecture5.pptx
 
Multimedia-Lecture-7.pptx
Multimedia-Lecture-7.pptxMultimedia-Lecture-7.pptx
Multimedia-Lecture-7.pptx
 
MultiMedia-Lecture-4.pptx
MultiMedia-Lecture-4.pptxMultiMedia-Lecture-4.pptx
MultiMedia-Lecture-4.pptx
 
Multimedia-Lecture-6.pptx
Multimedia-Lecture-6.pptxMultimedia-Lecture-6.pptx
Multimedia-Lecture-6.pptx
 
Multimedia-Lecture-3.pptx
Multimedia-Lecture-3.pptxMultimedia-Lecture-3.pptx
Multimedia-Lecture-3.pptx
 

Recently uploaded

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 

Recently uploaded (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 

Jsp and jstl

  • 2. Introduction to JSP  It stands for Java Server Pages.  It is a server side technology.  It is used for creating web application.  It is used to create dynamic web content.  In this JSP tags are used to insert JAVA code into HTML pages.  It is an advanced version of Servlet Technology.  It is a Web based technology helps us to create dynamic and platform independent web pages.  In this, Java code can be inserted in HTML/ XML pages or both.  JSP is first converted into servlet by JSP container before processing the client’s request.
  • 3. JSP pages are more advantageous than Servlet:  They are easy to maintain.  No recompilation or redeployment is required.  JSP has access to entire API of JAVA .  JSP are extended version of Servlet
  • 4. Features of JSP  Coding in JSP is easy :- As it is just adding JAVA code to HTML/XML.  Reduction in the length of Code :- In JSP we use action tags, custom tags etc.  Connection to Database is easier :-It is easier to connect website to database and allows to read or write data easily to the database.  Make Interactive websites :- In this we can create dynamic web pages which helps user to interact in real time environment.  Portable, Powerful, flexible and easy to maintain :- as these are browser and server independent.  No Redeployment and No Re-Compilation :- It is dynamic, secure and platform independent so no need to re-compilation.  Extension to Servlet :- as it has all features of servlets, implicit objects and custom tags
  • 5. syntax  Declaration Tag :-It is used to declare variables. Syntax:- <%! Dec var %> Example:- <%! int var=10; %> Syntax:- <%= expression %> Example:- <% num1 = num1+num2 %> Syntax:- <% -- JSP Comments %>
  • 6. How to run JSP in Eclipse IDE using Apache Tomcat Server Step 1: In order to run JSP in Eclipse IDE, you need to have Apache tomcat Server configured in Eclipse IDE.
  • 8. Give a Project name and click Finish.
  • 9. Create a JSP file. Right click on the WebContent-> New -> Click on JSP File
  • 10. Enter file name and click Finish.
  • 11. Write some JSP codeRun the JSP project. Right click on your JSP project -> Run as -> Click on “Run on Server”.
  • 12. Select the Server and click next.
  • 13. Select the Server and click next.
  • 14. Click on Add All -> Click Finish
  • 15. JSP - Standard Tag Library  The JavaServer Pages Standard Tag Library (JSTL) is a collection of useful JSP tags which encapsulates the core functionality common to many JSP applications.  JSTL has support for common, structural tasks such as iteration and conditionals, tags for manipulating XML documents, internationalization tags, and SQL tags. It also provides a framework for integrating the existing custom tags with the JSTL tags.
  • 16. Advantage of JSTL  Fast Development JSTL provides many tags that simplify the JSP.  Code Reusability We can use the JSTL tags on various pages.  No need to use scriptlet tag It avoids the use of scriptlet tag.
  • 17. Install JSTL Library To begin working with JSP tages you need to first install the JSTL library. If you are using the Apache Tomcat container, then follow these two steps − Step 1 − Download the binary distribution from Apache Standard Taglib and unpack the compressed file. Step 2 − To use the Standard Taglib from its Jakarta Taglibs distribution, simply copy the JAR files in the distribution's 'lib' directory to your application's webappsROOTWEB- INFlib directory. To use any of the libraries, you must include a <taglib> directive at the top of each JSP that uses the library.
  • 18.
  • 19. Classification of The JSTL Tags The JSTL tags can be classified, according to their functions, into the following JSTL tag library groups that can be used when creating a JSP page −  Core Tags  Formatting tags  SQL tags  XML tags  JSTL Functions
  • 20. Core Tags S.No. Tag & Description 1 <c:out>Like <%= ... >, but for expressions. 2 <c:set >Sets the result of an expression evaluation in a 'scope' 3 <c:remove >Removes a scoped variable (from a particular scope, if specified). 4 <c:catch>Catches any Throwable that occurs in its body and optionally exposes it. 5 <c:if>Simple conditional tag which evalutes its body if the supplied condition is true. 6 <c:choose>Simple conditional tag that establishes a context for mutually exclusive conditional operations, marked by <when> and <otherwise>. 7 <c:when>Subtag of <choose> that includes its body if its condition evalutes to 'true'. 8 <c:otherwise >Subtag of <choose> that follows the <when> tags and runs only if all of the prior conditions evaluated to 'false'. 9 <c:import>Retrieves an absolute or relative URL and exposes its contents to either the page, a String in 'var', or a Reader in 'varReader'. 10 <c:forEach >The basic iteration tag, accepting many different collection types and supporting subsetting and other functionality . 11 <c:forTokens>Iterates over tokens, separated by the supplied delimeters. 12 <c:param>Adds a parameter to a containing 'import' tag's URL. 13 <c:redirect >Redirects to a new URL. 14 <c:url>Creates a URL with optional query parameters
  • 21. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <html> <head> <title>Tag Example</title> </head> <body> <c:out value="${'Welcome to JSTL'}"/> </body> </html>
  • 22. Java Servlet and JDBC Example | Insert data in MySQL to start with interfacing Java Servlet Program with JDBC Connection:  Proper JDBC Environment should set-up along with database creation.  To do so, download the mysql-connector.jar file from the internet,  As it is downloaded, move the jar file to the apache- tomcat server folder,  Place the file in lib folder present in the apache- tomcat directory.  To start with the basic concept of interfacing:  Step 1: Creation of Database and Table in MySQL
  • 23. Step 2: Implementation of required Web-pages <html> <head> <title>Insert Data</title> </head> <body> <form action="./InsertData" method="post"> <p>ID:</p> <input type="text" name="id"/> <br/> <p>String:</p> <input type="text" name="string"/> <br/><br/><br/> <input type="submit"/> </form> </body> </html>
  • 24. Step 3: Creation of Java Servlet program with JDBC Connection to create a JDBC Connection steps are 1. Import all the packages 2. Register the JDBC Driver 3. Open a connection 4. Execute the query, and retrieve the result 5. Clean up the JDBC Environment 6. Create a separate class to create a connection of database, as it is a lame process to writing the same code snippet in all the program. Create a .java file which returns a Connection object.
  • 25. import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; // This class can be used to initialize the database connection public class DatabaseConnection { protected static Connection initializeDatabase() throws SQLException, ClassNotFoundException { // Initialize all the information regarding // Database Connection String dbDriver = "com.mysql.jdbc.Driver"; String dbURL = "jdbc:mysql:// localhost:3306/"; // Database name to access String dbName = "demoprj"; String dbUsername = "root"; String dbPassword = "root"; Class.forName(dbDriver); Connection con = DriverManager.getConnection(dbURL + dbName, dbUsername, dbPassword); return con; } }
  • 26. To use this class method, create an object in Java Servlet programBelow program shows Servlet Class which create a connection and insert the data in the demo table, import java.io.IOException; import java.io.PrintWriter; import java.sql.Connection; import java.sql.PreparedStatement; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse ; // Import Database Connection Class file import code.DatabaseConnection; protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { // Initialize the database Connection con = DatabaseConnection.initializeDatabase(); // Create a SQL query to insert data into demo table // demo table consists of two columns, so two '?' is used PreparedStatement st = con .prepareStatement("insert into demo values(?, ?)"); // For the first parameter, // get the data using request object // sets the data to st pointer st.setInt(1, Integer.valueOf(request.getParameter("id"))); // Same for second parameter st.setString(2, request.getParameter("string")); // Execute the insert command using executeUpdate() // to make changes in database st.executeUpdate(); // Close all the connections st.close(); con.close(); // Get a writer pointer // to display the successful result PrintWriter out = response.getWriter(); out.println("<html><body><b>Successfully Inserted" + "</b></body></html>"); } catch (Exception e) { e.printStackTrace(); } } }
  • 27. step 5: Get the data from the HTML fileTo get the data from the HTML file, the request object is used which calls getParameter() Method to fetch the data from the channel. After successful insertion, the writer object is created to display a success message.  After insertion operation from Servlet, data will be reflected in MySQL Database