SlideShare a Scribd company logo
IMRAN DAUD
FOUNDATION UNIVERSITY
INSTITUTE OF MANAGEMENT AND
COMPUTER SCIENCES
Imran Daud
FUIMCS
Web Engineering
JSP
Intro to JSP
 Sun‟s Solution for developing dynamic websites.
 Server side scripting support for creating database
driven web applications.
 Web file always has „.jsp‟ extension.
 Insert java code into JSP file.
 On receiving request, JSP pages are loaded into
server memory for its execution.
 JSP Services are efficient and client is served in short
period of time.
Web-Server for JSP
 Number of web-servers are available.
 Apache TomCat
 WebSphere
 GalssFish
 etc
Setup NetBeans
 Start NetBeans
 Goto File->New Project…
Name & Location for Project
Choose Web-Server
Install New Web-Server
Installation and Login Details
First Install
required
web-server.
Give server
location
Username &
Password
We use Already Installed with NetBeans
Test Web-Server
 Run jsp file to test server by clicking green play
button.
JSP Tags
 <% (scriptless)
 <@ (directive page, include and taglib)
 <%-- (comment)
JSP Tags
 Directives
In the directives we can import packages, define error handling
pages or the session information of the JSP page.
 Declarations
This tag is used for defining the functions and variables to be used
in the JSP.
 Scriplets
In this tag we can insert any amount of valid java code and these
codes are placed in _jspService method by the JSP engine.
 Expressions
We can use this tag to output any data on the generated page. These
data are automatically converted to string and printed on the output
stream
Directive
<%@directive attribute="value" %>
 Where directive may be:
 page: page is used to provide the information about it.
Example: <%@page language="java" %>
 include: include is used to include a file in the JSP page.
Example: <%@ include file="/header.jsp" %>
 taglib: taglib is used to use the custom tags in the JSP pages
(custom tags allows us to defined our own tags).
Example: <%@ taglib uri="tlds/taglib.tld" prefix="mytag" %>
Attributes can be
 language="java"
This tells the server that the page is using the java language. Current JSP specification supports
only java language.
Example: <%@page language="java" %>
 extends="mypackage.myclass"
This attribute is used when we want to extend any class. We can use comma(,) to import more
than one packages.
Example: <%@page language="java" import="java.sql.*,mypackage.myclass" %>
 session="true"
When this value is true session data is available to the JSP page otherwise not. By default this
value is true.
Example: <%@page language="java" session="true" %>
 errorPage="error.jsp"
errorPage is used to handle the un-handled exceptions in the page.
Example: <%@page language="java" session="true" errorPage="error.jsp" %>
 contentType="text/html;charset=ISO-8859-1"
Use this attribute to set the mime type and character set of the JSP.
Example: <%@page language="java" session="true" contentType="text/html;charset=ISO-
8859-1" %>
Adding Scriptless
 <% opening tag
 %> closing tag
 To print message<% =“Hello World” %>
 To print <% = new java.util.Date() %>
JSP Declarations
 you must use the <%! and %> sequences to enclose
your declarations.
<%!
Date theDate = new Date();
Date getDate() {
out.println( "In getDate() method");
return theDate;
}
%>
Hello! The time is now <%= getDate() %>
Practice
 Make website counter…….
Declaration and Website Counter
<%!
 static int i=0;
 private int getCount(){
 return ++i;
 }
%>
<%=getCount()%>
Variables in Scriptless
 request:
request represents the clients request and is a subclass of HttpServletRequest. Use
this variable to retrieve the data submitted along the request.
Example:
<%
//java codes
String userName=null;
userName=request.getParameter("userName");
%>
 response:
response is subclass of HttpServletResponse.
 session:
session represents the HTTP session object associated with the request.
 out:
out is an object of output stream and is used to send any output to the client.
Handling „Request‟
 Steps
 Make index page with „form‟ containing username and
password.
 Use post or get method within form tag.
 Make two buttons submit and rest.
 Handle request in another jsp page.
 Methods to use are:
 Request
 Pagecontext(to redirect page)
Request methods
 very useful pre-defined variable is "request".
 It is of type javax.servlet.http.HttpServletRequest
 <%
request.getRemoteHoste(); or
request.getRemoteAddr();
 %>
JSP Session
 Associate any data with session by using .
 As long as session is maintained with user data will
be accessible on any page of website.
 Session object is associated with each user visiting
that website.
 Example: Associate username with session with
website of three pages.
How to Mix Scriptless and HTML
Import package
 <%@page import="java.util.*" %>
 <HTML>
 <BODY>
<% System.out.println( "Evaluating date now" );
Date date = new Date();
 %>
 Hello! The time is now
 <%= date %>
 </BODY>
 </HTML>
JSP Beans
 JSP introduces another organized way to retrieve
form data (but also supports other functionalities).
 That is by introducing bean.(This is not full beans)
 Define java with settter and
getter functions.
Bean Proporties
 i) It has a public no-args constructor
 ii) It has 'set' and 'get' methods for its properties.
 iii) It may have any general functions.
Steps in Creating JSP Beans
 Create html page with form data by setting action
page.
 Create java class with setter and getter function with
same name as defined in form fccccdcx.
 Create JSP page that will handle request data with
following tags.
 <jsp:useBean id=“mybean” class=“package.className"
scope="session"/>
 <jsp:setProperty name="mybean" property="*" />
 Retrieve data by following command.
 <%=mybean.getPassword()%>
Scope of Bean
 Scope= “Page” (only in current page of page specified)
 Scope = “request” (within request)
 Scope = “session” (all pages)
 If we access parameter in third page using „request‟
object then it shows null value.
 But same can be accessed using session object, if
scope is set to session.
 Now we can also access parameter through „request‟
object with following command in 2nd page.
 <jsp:forward page="session.jsp" />
 Use following to include page in existing page
 <jsp:include = “page.jsp” flush = “false” />
Quiz
 Use beans to make website counter……
Tag Libraries
 Also known as custom tags defined by user.
 Use to initiate any custom action.
 Custom actions include form processing, accessing
databases and other enterprise services such as email
and directories, and flow control.
Features of Custom Tags
 They can be customized via attributes passed from the calling
page.
 They have access to all the objects available to JSP pages.
 They can modify the response generated by the calling page.
 They can communicate with each other. You can create and
initialize a JavaBeans component, create a variable that refers
to that bean in one tag, and then use the bean in another tag.
 They can be nested within one another, allowing for complex
interactions within a JSP page.
Custom Tags
 Declare Tag Libraries
 <%@ taglib uri="/tlt" prefix="tlt" %>
 „Uri‟ attribute refers to a URI that uniquely identifies the tag
library.
 The prefix attribute distinguishes tags provided by a given tag
library from those provided by other tag libraries.
Steps
To define a tag, you need to:
 First declare the tags in a tag library
descriptor(TLD).
 Develop a tag handler and helper classes for the tag.
Tag Handler
Tag Handler
 Tag handler object is invoked by jsp container to
evaluate custom tag.
 This tag handler is java file with all custom actions
defined in it.
 We only use overridden functions
Classes to Import for handler
 TagSupport
 SimpleTagSupport
Tag Library Descriptor (TLD)
How to ?
 Create New File Tag Library Descriptor.
 Create Tag Handler file.
 Set functionality in tag handler. (once tag handler file is created
it automatically will write basic tags in TLD file).
 Call custom tag using following
 <%@taglib uri="mytld" prefix="mytag" %>
 <mytag:mytaghandler/>
Database
 Pre-Req:
 MySQL Server
 MySQL Workbench
 Create Database with table and attributes.
 WAMP Server
 Important
 Include SQL Library in Library folder before stating to
implement your project.
Steps to follow
 Import SQL Package in JSP File
 <%@ page language="java" import="java.sql.*" %>
 Load MySQL Driver
 Class.forName("com.mysql.jdbc.Driver");
 Create Connection with SQL Server
 Connection c=DriverManager.getConnection("jdbc:mysql://
localhost:3300/mydb","root", "123");
 Statement s= c.createStatement();
 ResultSet
 Statement
 ResultSet rs=s.executeQuery("Select * from student");
Show Results
 while (rs.next())
 {
out.println(rs.getString("myfield")+"<br>");
}
JSTL Use
 JSTL Tags are used for
 Iteration and conditionals
 Tags for manipulating XML documents
 Internationalization tags
 SQL tags.
JSTL
JSTL Steps
 Add JSTL library by right clicking on library folder of
project.
 To use JSTL in JSP file use following
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"
%>
JSTL Core Tags
JSTL SQL Tags
JSTL Functions
JSTL Format Tags
Reference
 http://www.csl.mtu.edu/cs2321/
 Netbeans.org
 Roseindia.net
 Jsptut.com
 tutorialspoint.com/jsp

More Related Content

What's hot

Implicit object.pptx
Implicit object.pptxImplicit object.pptx
Implicit object.pptx
chakrapani tripathi
 
jsp MySQL database connectivity
jsp MySQL database connectivityjsp MySQL database connectivity
jsp MySQL database connectivity
baabtra.com - No. 1 supplier of quality freshers
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
BG Java EE Course
 
Jsp
JspJsp
Jsp chapter 1
Jsp chapter 1Jsp chapter 1
Jsp chapter 1
kamal kotecha
 
Servlet and jsp interview questions
Servlet and jsp interview questionsServlet and jsp interview questions
Servlet and jsp interview questions
Sujata Regoti
 
Spring Web Views
Spring Web ViewsSpring Web Views
Spring Web Views
Emprovise
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
Vikas Jagtap
 
Java server pages
Java server pagesJava server pages
Java server pages
Tanmoy Barman
 
JSP Error handling
JSP Error handlingJSP Error handling
JSP Error handling
kamal kotecha
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
Kasun Madusanke
 
RubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendallRubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendalltutorialsruby
 
Jsp sasidhar
Jsp sasidharJsp sasidhar
Jsp sasidhar
Sasidhar Kothuru
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
Atul Saurabh
 
Lap trinh web [Slide jsp]
Lap trinh web [Slide jsp]Lap trinh web [Slide jsp]
Lap trinh web [Slide jsp]
Tri Nguyen
 
Jsp Introduction Tutorial
Jsp Introduction TutorialJsp Introduction Tutorial
Jsp Introduction Tutorial
APSMIND TECHNOLOGY PVT LTD.
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsCarol McDonald
 

What's hot (19)

Implicit object.pptx
Implicit object.pptxImplicit object.pptx
Implicit object.pptx
 
jsp MySQL database connectivity
jsp MySQL database connectivityjsp MySQL database connectivity
jsp MySQL database connectivity
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Jsp
JspJsp
Jsp
 
Jsp chapter 1
Jsp chapter 1Jsp chapter 1
Jsp chapter 1
 
Servlet and jsp interview questions
Servlet and jsp interview questionsServlet and jsp interview questions
Servlet and jsp interview questions
 
Spring Web Views
Spring Web ViewsSpring Web Views
Spring Web Views
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
19servlets
19servlets19servlets
19servlets
 
Java server pages
Java server pagesJava server pages
Java server pages
 
JSP Error handling
JSP Error handlingJSP Error handling
JSP Error handling
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
RubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendallRubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendall
 
Jsp sasidhar
Jsp sasidharJsp sasidhar
Jsp sasidhar
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
 
Lap trinh web [Slide jsp]
Lap trinh web [Slide jsp]Lap trinh web [Slide jsp]
Lap trinh web [Slide jsp]
 
Jsp Introduction Tutorial
Jsp Introduction TutorialJsp Introduction Tutorial
Jsp Introduction Tutorial
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.js
 

Viewers also liked

Joomla!: phpMyAdmin for Beginners
Joomla!: phpMyAdmin for BeginnersJoomla!: phpMyAdmin for Beginners
Joomla!: phpMyAdmin for Beginners
Yireo
 
Using XAMPP
Using XAMPPUsing XAMPP
Using XAMPPbutest
 
phpMyAdmin con Xampp
phpMyAdmin con XamppphpMyAdmin con Xampp
phpMyAdmin con Xampp
LeccionesWeb
 
Introducing the MySQL Workbench CASE tool
Introducing the MySQL Workbench CASE toolIntroducing the MySQL Workbench CASE tool
Introducing the MySQL Workbench CASE tool
András Bögöly
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/Servlet
Sunil OS
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
FAKHRUN NISHA
 
MySQL Database with phpMyAdmin
MySQL Database with  phpMyAdminMySQL Database with  phpMyAdmin
MySQL Database with phpMyAdmin
Karwan Mustafa Kareem
 
Introduction to xampp
Introduction to xamppIntroduction to xampp
Introduction to xamppJin Castor
 
Jsp
JspJsp
Java Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP BasicJava Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP Basic
IMC Institute
 
JSF2 and JSP
JSF2 and JSPJSF2 and JSP
JSF2 and JSP
Armen Arzumanyan
 

Viewers also liked (15)

xampp_server
xampp_serverxampp_server
xampp_server
 
Joomla!: phpMyAdmin for Beginners
Joomla!: phpMyAdmin for BeginnersJoomla!: phpMyAdmin for Beginners
Joomla!: phpMyAdmin for Beginners
 
Jsp Presentation +Mufix "3"
Jsp Presentation +Mufix "3"Jsp Presentation +Mufix "3"
Jsp Presentation +Mufix "3"
 
Using XAMPP
Using XAMPPUsing XAMPP
Using XAMPP
 
phpMyAdmin con Xampp
phpMyAdmin con XamppphpMyAdmin con Xampp
phpMyAdmin con Xampp
 
Introducing the MySQL Workbench CASE tool
Introducing the MySQL Workbench CASE toolIntroducing the MySQL Workbench CASE tool
Introducing the MySQL Workbench CASE tool
 
Jsp
JspJsp
Jsp
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/Servlet
 
Java/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBCJava/Servlet/JSP/JDBC
Java/Servlet/JSP/JDBC
 
MySQL Database with phpMyAdmin
MySQL Database with  phpMyAdminMySQL Database with  phpMyAdmin
MySQL Database with phpMyAdmin
 
Introduction to xampp
Introduction to xamppIntroduction to xampp
Introduction to xampp
 
Jsp
JspJsp
Jsp
 
Java Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP BasicJava Web Programming [4/9] : JSP Basic
Java Web Programming [4/9] : JSP Basic
 
Xampp installation
Xampp installation Xampp installation
Xampp installation
 
JSF2 and JSP
JSF2 and JSPJSF2 and JSP
JSF2 and JSP
 

Similar to 4. jsp

Jsp in Servlet by Rj
Jsp in Servlet by RjJsp in Servlet by Rj
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
Yoga Raja
 
Introduction to JSP.pptx
Introduction to JSP.pptxIntroduction to JSP.pptx
Introduction to JSP.pptx
ManishaPatil932723
 
Jsp
JspJsp
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Ayes Chinmay
 
Jsp and jstl
Jsp and jstlJsp and jstl
Jsp and jstl
vishal choudhary
 
JSP.pptx
JSP.pptxJSP.pptx
JSP.pptx
NishaRohit6
 
Atul & shubha goswami jsp
Atul & shubha goswami jspAtul & shubha goswami jsp
Atul & shubha goswami jsp
Atul Giri
 
Introduction to JSP
Introduction to JSPIntroduction to JSP
Introduction to JSPGeethu Mohan
 
JSP Components and Directives.pdf
JSP Components and Directives.pdfJSP Components and Directives.pdf
JSP Components and Directives.pdf
Arumugam90
 
Jsp1
Jsp1Jsp1
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
WebStackAcademy
 
J2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsJ2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - Components
Kaml Sah
 
Jsp
JspJsp
JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGES
Kalpana T
 
JSP AND XML USING JAVA WITH GET AND POST METHODS
JSP AND XML USING JAVA WITH GET AND POST METHODSJSP AND XML USING JAVA WITH GET AND POST METHODS
JSP AND XML USING JAVA WITH GET AND POST METHODS
bharathiv53
 
Jsp
JspJsp
DataBase Connectivity
DataBase ConnectivityDataBase Connectivity
DataBase ConnectivityAkankshaji
 

Similar to 4. jsp (20)

Jsp in Servlet by Rj
Jsp in Servlet by RjJsp in Servlet by Rj
Jsp in Servlet by Rj
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
 
Introduction to JSP.pptx
Introduction to JSP.pptxIntroduction to JSP.pptx
Introduction to JSP.pptx
 
Jsp
JspJsp
Jsp
 
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
 
Jsp and jstl
Jsp and jstlJsp and jstl
Jsp and jstl
 
JSP.pptx
JSP.pptxJSP.pptx
JSP.pptx
 
Atul & shubha goswami jsp
Atul & shubha goswami jspAtul & shubha goswami jsp
Atul & shubha goswami jsp
 
Introduction to JSP
Introduction to JSPIntroduction to JSP
Introduction to JSP
 
JSP Components and Directives.pdf
JSP Components and Directives.pdfJSP Components and Directives.pdf
JSP Components and Directives.pdf
 
Jsp1
Jsp1Jsp1
Jsp1
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
 
J2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - ComponentsJ2EE - JSP-Servlet- Container - Components
J2EE - JSP-Servlet- Container - Components
 
Jsp
JspJsp
Jsp
 
JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGES
 
JSP AND XML USING JAVA WITH GET AND POST METHODS
JSP AND XML USING JAVA WITH GET AND POST METHODSJSP AND XML USING JAVA WITH GET AND POST METHODS
JSP AND XML USING JAVA WITH GET AND POST METHODS
 
Jsp
JspJsp
Jsp
 
Jsp
JspJsp
Jsp
 
DataBase Connectivity
DataBase ConnectivityDataBase Connectivity
DataBase Connectivity
 
Web&java. jsp
Web&java. jspWeb&java. jsp
Web&java. jsp
 

More from AnusAhmad

[Www.pkbulk.blogspot.com]file and indexing
[Www.pkbulk.blogspot.com]file and indexing[Www.pkbulk.blogspot.com]file and indexing
[Www.pkbulk.blogspot.com]file and indexing
AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms12
[Www.pkbulk.blogspot.com]dbms12[Www.pkbulk.blogspot.com]dbms12
[Www.pkbulk.blogspot.com]dbms12
AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms11
[Www.pkbulk.blogspot.com]dbms11[Www.pkbulk.blogspot.com]dbms11
[Www.pkbulk.blogspot.com]dbms11
AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10
AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms09
[Www.pkbulk.blogspot.com]dbms09[Www.pkbulk.blogspot.com]dbms09
[Www.pkbulk.blogspot.com]dbms09
AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms07
[Www.pkbulk.blogspot.com]dbms07[Www.pkbulk.blogspot.com]dbms07
[Www.pkbulk.blogspot.com]dbms07
AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms06
[Www.pkbulk.blogspot.com]dbms06[Www.pkbulk.blogspot.com]dbms06
[Www.pkbulk.blogspot.com]dbms06
AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms05
[Www.pkbulk.blogspot.com]dbms05[Www.pkbulk.blogspot.com]dbms05
[Www.pkbulk.blogspot.com]dbms05
AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms04
[Www.pkbulk.blogspot.com]dbms04[Www.pkbulk.blogspot.com]dbms04
[Www.pkbulk.blogspot.com]dbms04
AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms03
[Www.pkbulk.blogspot.com]dbms03[Www.pkbulk.blogspot.com]dbms03
[Www.pkbulk.blogspot.com]dbms03
AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms02
[Www.pkbulk.blogspot.com]dbms02[Www.pkbulk.blogspot.com]dbms02
[Www.pkbulk.blogspot.com]dbms02
AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms01
[Www.pkbulk.blogspot.com]dbms01[Www.pkbulk.blogspot.com]dbms01
[Www.pkbulk.blogspot.com]dbms01
AnusAhmad
 
[Www.pkbulk.blogspot.com]dbms13
[Www.pkbulk.blogspot.com]dbms13[Www.pkbulk.blogspot.com]dbms13
[Www.pkbulk.blogspot.com]dbms13
AnusAhmad
 
9. java server faces
9. java server faces9. java server faces
9. java server faces
AnusAhmad
 
8. java script
8. java script8. java script
8. java script
AnusAhmad
 
7. struts
7. struts7. struts
7. struts
AnusAhmad
 
5. servlets
5. servlets5. servlets
5. servlets
AnusAhmad
 
3. applets
3. applets3. applets
3. applets
AnusAhmad
 
2. http, html
2. http, html2. http, html
2. http, html
AnusAhmad
 
1. intro
1. intro1. intro
1. intro
AnusAhmad
 

More from AnusAhmad (20)

[Www.pkbulk.blogspot.com]file and indexing
[Www.pkbulk.blogspot.com]file and indexing[Www.pkbulk.blogspot.com]file and indexing
[Www.pkbulk.blogspot.com]file and indexing
 
[Www.pkbulk.blogspot.com]dbms12
[Www.pkbulk.blogspot.com]dbms12[Www.pkbulk.blogspot.com]dbms12
[Www.pkbulk.blogspot.com]dbms12
 
[Www.pkbulk.blogspot.com]dbms11
[Www.pkbulk.blogspot.com]dbms11[Www.pkbulk.blogspot.com]dbms11
[Www.pkbulk.blogspot.com]dbms11
 
[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10[Www.pkbulk.blogspot.com]dbms10
[Www.pkbulk.blogspot.com]dbms10
 
[Www.pkbulk.blogspot.com]dbms09
[Www.pkbulk.blogspot.com]dbms09[Www.pkbulk.blogspot.com]dbms09
[Www.pkbulk.blogspot.com]dbms09
 
[Www.pkbulk.blogspot.com]dbms07
[Www.pkbulk.blogspot.com]dbms07[Www.pkbulk.blogspot.com]dbms07
[Www.pkbulk.blogspot.com]dbms07
 
[Www.pkbulk.blogspot.com]dbms06
[Www.pkbulk.blogspot.com]dbms06[Www.pkbulk.blogspot.com]dbms06
[Www.pkbulk.blogspot.com]dbms06
 
[Www.pkbulk.blogspot.com]dbms05
[Www.pkbulk.blogspot.com]dbms05[Www.pkbulk.blogspot.com]dbms05
[Www.pkbulk.blogspot.com]dbms05
 
[Www.pkbulk.blogspot.com]dbms04
[Www.pkbulk.blogspot.com]dbms04[Www.pkbulk.blogspot.com]dbms04
[Www.pkbulk.blogspot.com]dbms04
 
[Www.pkbulk.blogspot.com]dbms03
[Www.pkbulk.blogspot.com]dbms03[Www.pkbulk.blogspot.com]dbms03
[Www.pkbulk.blogspot.com]dbms03
 
[Www.pkbulk.blogspot.com]dbms02
[Www.pkbulk.blogspot.com]dbms02[Www.pkbulk.blogspot.com]dbms02
[Www.pkbulk.blogspot.com]dbms02
 
[Www.pkbulk.blogspot.com]dbms01
[Www.pkbulk.blogspot.com]dbms01[Www.pkbulk.blogspot.com]dbms01
[Www.pkbulk.blogspot.com]dbms01
 
[Www.pkbulk.blogspot.com]dbms13
[Www.pkbulk.blogspot.com]dbms13[Www.pkbulk.blogspot.com]dbms13
[Www.pkbulk.blogspot.com]dbms13
 
9. java server faces
9. java server faces9. java server faces
9. java server faces
 
8. java script
8. java script8. java script
8. java script
 
7. struts
7. struts7. struts
7. struts
 
5. servlets
5. servlets5. servlets
5. servlets
 
3. applets
3. applets3. applets
3. applets
 
2. http, html
2. http, html2. http, html
2. http, html
 
1. intro
1. intro1. intro
1. intro
 

Recently uploaded

The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 

Recently uploaded (20)

The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 

4. jsp

  • 1. IMRAN DAUD FOUNDATION UNIVERSITY INSTITUTE OF MANAGEMENT AND COMPUTER SCIENCES Imran Daud FUIMCS Web Engineering JSP
  • 2. Intro to JSP  Sun‟s Solution for developing dynamic websites.  Server side scripting support for creating database driven web applications.  Web file always has „.jsp‟ extension.  Insert java code into JSP file.  On receiving request, JSP pages are loaded into server memory for its execution.  JSP Services are efficient and client is served in short period of time.
  • 3. Web-Server for JSP  Number of web-servers are available.  Apache TomCat  WebSphere  GalssFish  etc
  • 4. Setup NetBeans  Start NetBeans  Goto File->New Project…
  • 5. Name & Location for Project
  • 8. Installation and Login Details First Install required web-server. Give server location Username & Password
  • 9. We use Already Installed with NetBeans
  • 10.
  • 11.
  • 12. Test Web-Server  Run jsp file to test server by clicking green play button.
  • 13. JSP Tags  <% (scriptless)  <@ (directive page, include and taglib)  <%-- (comment)
  • 14. JSP Tags  Directives In the directives we can import packages, define error handling pages or the session information of the JSP page.  Declarations This tag is used for defining the functions and variables to be used in the JSP.  Scriplets In this tag we can insert any amount of valid java code and these codes are placed in _jspService method by the JSP engine.  Expressions We can use this tag to output any data on the generated page. These data are automatically converted to string and printed on the output stream
  • 15. Directive <%@directive attribute="value" %>  Where directive may be:  page: page is used to provide the information about it. Example: <%@page language="java" %>  include: include is used to include a file in the JSP page. Example: <%@ include file="/header.jsp" %>  taglib: taglib is used to use the custom tags in the JSP pages (custom tags allows us to defined our own tags). Example: <%@ taglib uri="tlds/taglib.tld" prefix="mytag" %>
  • 16. Attributes can be  language="java" This tells the server that the page is using the java language. Current JSP specification supports only java language. Example: <%@page language="java" %>  extends="mypackage.myclass" This attribute is used when we want to extend any class. We can use comma(,) to import more than one packages. Example: <%@page language="java" import="java.sql.*,mypackage.myclass" %>  session="true" When this value is true session data is available to the JSP page otherwise not. By default this value is true. Example: <%@page language="java" session="true" %>  errorPage="error.jsp" errorPage is used to handle the un-handled exceptions in the page. Example: <%@page language="java" session="true" errorPage="error.jsp" %>  contentType="text/html;charset=ISO-8859-1" Use this attribute to set the mime type and character set of the JSP. Example: <%@page language="java" session="true" contentType="text/html;charset=ISO- 8859-1" %>
  • 17. Adding Scriptless  <% opening tag  %> closing tag  To print message<% =“Hello World” %>  To print <% = new java.util.Date() %>
  • 18. JSP Declarations  you must use the <%! and %> sequences to enclose your declarations. <%! Date theDate = new Date(); Date getDate() { out.println( "In getDate() method"); return theDate; } %> Hello! The time is now <%= getDate() %>
  • 19. Practice  Make website counter…….
  • 20. Declaration and Website Counter <%!  static int i=0;  private int getCount(){  return ++i;  } %> <%=getCount()%>
  • 21. Variables in Scriptless  request: request represents the clients request and is a subclass of HttpServletRequest. Use this variable to retrieve the data submitted along the request. Example: <% //java codes String userName=null; userName=request.getParameter("userName"); %>  response: response is subclass of HttpServletResponse.  session: session represents the HTTP session object associated with the request.  out: out is an object of output stream and is used to send any output to the client.
  • 22. Handling „Request‟  Steps  Make index page with „form‟ containing username and password.  Use post or get method within form tag.  Make two buttons submit and rest.  Handle request in another jsp page.  Methods to use are:  Request  Pagecontext(to redirect page)
  • 23. Request methods  very useful pre-defined variable is "request".  It is of type javax.servlet.http.HttpServletRequest  <% request.getRemoteHoste(); or request.getRemoteAddr();  %>
  • 24. JSP Session  Associate any data with session by using .  As long as session is maintained with user data will be accessible on any page of website.  Session object is associated with each user visiting that website.  Example: Associate username with session with website of three pages.
  • 25. How to Mix Scriptless and HTML
  • 26. Import package  <%@page import="java.util.*" %>  <HTML>  <BODY> <% System.out.println( "Evaluating date now" ); Date date = new Date();  %>  Hello! The time is now  <%= date %>  </BODY>  </HTML>
  • 27. JSP Beans  JSP introduces another organized way to retrieve form data (but also supports other functionalities).  That is by introducing bean.(This is not full beans)  Define java with settter and getter functions.
  • 28. Bean Proporties  i) It has a public no-args constructor  ii) It has 'set' and 'get' methods for its properties.  iii) It may have any general functions.
  • 29. Steps in Creating JSP Beans  Create html page with form data by setting action page.  Create java class with setter and getter function with same name as defined in form fccccdcx.  Create JSP page that will handle request data with following tags.  <jsp:useBean id=“mybean” class=“package.className" scope="session"/>  <jsp:setProperty name="mybean" property="*" />  Retrieve data by following command.  <%=mybean.getPassword()%>
  • 30. Scope of Bean  Scope= “Page” (only in current page of page specified)  Scope = “request” (within request)  Scope = “session” (all pages)
  • 31.  If we access parameter in third page using „request‟ object then it shows null value.  But same can be accessed using session object, if scope is set to session.  Now we can also access parameter through „request‟ object with following command in 2nd page.  <jsp:forward page="session.jsp" />  Use following to include page in existing page  <jsp:include = “page.jsp” flush = “false” />
  • 32. Quiz  Use beans to make website counter……
  • 33. Tag Libraries  Also known as custom tags defined by user.  Use to initiate any custom action.  Custom actions include form processing, accessing databases and other enterprise services such as email and directories, and flow control.
  • 34. Features of Custom Tags  They can be customized via attributes passed from the calling page.  They have access to all the objects available to JSP pages.  They can modify the response generated by the calling page.  They can communicate with each other. You can create and initialize a JavaBeans component, create a variable that refers to that bean in one tag, and then use the bean in another tag.  They can be nested within one another, allowing for complex interactions within a JSP page.
  • 35. Custom Tags  Declare Tag Libraries  <%@ taglib uri="/tlt" prefix="tlt" %>  „Uri‟ attribute refers to a URI that uniquely identifies the tag library.  The prefix attribute distinguishes tags provided by a given tag library from those provided by other tag libraries.
  • 36. Steps To define a tag, you need to:  First declare the tags in a tag library descriptor(TLD).  Develop a tag handler and helper classes for the tag.
  • 37. Tag Handler Tag Handler  Tag handler object is invoked by jsp container to evaluate custom tag.  This tag handler is java file with all custom actions defined in it.  We only use overridden functions
  • 38. Classes to Import for handler  TagSupport  SimpleTagSupport
  • 40. How to ?  Create New File Tag Library Descriptor.  Create Tag Handler file.  Set functionality in tag handler. (once tag handler file is created it automatically will write basic tags in TLD file).  Call custom tag using following  <%@taglib uri="mytld" prefix="mytag" %>  <mytag:mytaghandler/>
  • 41. Database  Pre-Req:  MySQL Server  MySQL Workbench  Create Database with table and attributes.  WAMP Server  Important  Include SQL Library in Library folder before stating to implement your project.
  • 42. Steps to follow  Import SQL Package in JSP File  <%@ page language="java" import="java.sql.*" %>  Load MySQL Driver  Class.forName("com.mysql.jdbc.Driver");  Create Connection with SQL Server  Connection c=DriverManager.getConnection("jdbc:mysql:// localhost:3300/mydb","root", "123");  Statement s= c.createStatement();  ResultSet  Statement  ResultSet rs=s.executeQuery("Select * from student");
  • 43. Show Results  while (rs.next())  { out.println(rs.getString("myfield")+"<br>"); }
  • 44. JSTL Use  JSTL Tags are used for  Iteration and conditionals  Tags for manipulating XML documents  Internationalization tags  SQL tags.
  • 45. JSTL
  • 46. JSTL Steps  Add JSTL library by right clicking on library folder of project.  To use JSTL in JSP file use following  <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  • 48.
  • 50.
  • 53. Reference  http://www.csl.mtu.edu/cs2321/  Netbeans.org  Roseindia.net  Jsptut.com  tutorialspoint.com/jsp