SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Javed Ahmed
Coleta Software solutions pvt. Ltd.
1. In IT term a Server is a computer program that provides services to other
computer programs(or Users ) in the same or other computers.
2. The computer in which server program runs is frequently referred as
Server(though it may be used for other purposes as well).
3. In a client server programming model a server is a program that awaits
and fulfills requests from client programs in the same or other computers.
A given application in a computer may function as a client which requests
for services from other programs.
4. Specific to the web, a web server is a computer program(housed in a
computer) that serves requested HTML pages or files. A web client is the
requesting program associated with the user. The web browser in your
computer is a client that requests HTML files from Web server.
What is Server
 A web site is a collection of web pages which are stored on a web server and
can be accessed from any where using a web browser. The purpose of a web
site is to share information over the network.
Web sites can be of two types:
 Static web sites
 Dynamic web sites
In a static web site, the information which is presented to the end user,
remain available on the server usually in the form of HTML pages. When a user
sends a request to a page, contents of the page are sent by the server as
response.
In a dynamic web site, server has programs which are executed when
a request is submitted by clients, these programs process requests and
generate HTML contents which are sent by the server as response to the
client.
What is static and Dynamic Web
Site
1. Client side programming generally refers to the class of programs on the
web that are executed client side by the user’s web browser OR by client
side we refer to code that is executed directly on the device that the user is
using.
2. Upon request, the necessary files are sent to the user’s computer by the web
server (or server) on which they reside.
3. The user’s web browser executes the script and then displays the
document.
4. Client side programming language example include javascript.
disadvantage:
 By viewing the file that contains the script users may be able to see the
source code.
What is Client side Side
Programming
1. Server side programming generally refers to the class of programs that are
written to be executed on the Server.
2. A request is generated to execute some program stored on the server.
3. Server in turn serves the request i,e, executes the requested code piece on
server and returns response.
4. Some of the languages used for building Server side application are:
Java, Php, Python, Ruby, etc.
Advantage over Client Side Programming:
 The User cannot see the source code and may not be even aware that
a script is executed.
What is Server Side
Programming
1. In early days of the web, server side programming was almost exclusively
performed by using combination of C programs, Perl scripts and Shell
scripts using the common gateway interface(CGI).
2. CGI is a protocol which provides standard rules for server to invoke
programs, to provide requested data to them and to receive the processed
result from them.
Drawbacks of CGI based web applications:
 .For each request a process is started by the server to execute CGI script, Process creation and destruction
results in extra overhead than actual processing time.
 If number of requests increase, it takes more time for sending response
 CGI scripts were platform dependent i,e, if the web application is to be deployed from windows to Linux
server or vice versa CGI script need to be recompiled for the target platform.
History of Server side
Programming

To remove the drawbacks of CGI protocol, Sun microsystem in
1988 introduced the Servlet API.
1. To remove the overhead of process creation and destruction, a
thread based request processing model is provided by servlet.
2. By facilitating the development of web based application in
java, problem of platform dependency is removed
Introduction of Servlets
Servlet term is used with two different meanings in two different contexts,
1. In the broader context it represents an API which facilitates development of
dynamic web applications
2. In the narrow context it represents a java class which is defined using this
API for processing requests in a web application.
This component is responsible for processing requests in web
application.
javax.servlet.Servlet is the main interface of the API, it provides
methods which define initialization, processing and destruction phase of a
Servlet. These methods are called servlet life cycle methods.
What is Servlet
Various life cycle methods of servlet are discussed below:
1. init(): This method defines Initialization. This method is invoked only once
just afte servlet object is created.
public void init(ServletConfig config);
2. Service(): This method is invoked by the server each time a request is
received for the servlet.It is used by the servlet for processing requests.
public void service(ServletRequest request, ServletResponse
response)throws ServletException, IOException.
3. Destroy():This method is invoked by the server only once just after the
servlet in unloaded. It can be used by the application programmer for
defining cleanup operations.
public void destroy();
Life cycle methods of a Servlet
A servlet program can be created by three ways:
i. By implementing a servlet interface.
ii. By inheriting GenericServlet class.
iii. By inheriting HttpServlet class.
Server side Program to check whether a number is Prime or not?
Presentation logic:
<form action=“primeServlet” method=“post”>
<center> Enter Number<Input type=“Text” name=“num”>
<Input type=“submit” value=“check”></center>
</form>
Skeleton of a Servlet program

Business logic: PrimeServlet.java
import javax.Servlet.*;
import javax.Servlet.http.*;
import java.io.*;
class PrimeServlet extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse
response)throws ServletException IOException
{ response.setContentType(“text/html”) ;
PrintWriter out=response.getWriter();
//request data is read
int p=Integer.parseInt(request.getParameter);
//Business logic is defined
int d=2;
while(num%d!=0)
d++;
if(num==d)
Out.println(“number is prime”);
else
out.println(“number is not prime”);
out.close
}
}

Deployment Descriptor(Web.xml): A web application’s deployment
descriptor describes the classes, resources and configuration of the application
and how the web server uses them to serve web requests. When the web server
receives a request for the application, it uses deployment descriptor to map the
URL of the request to code that ought to handle the request. The deployment
descriptor is a file named web.xml.
Web.xml for our program is as
<web-app>
<servlet>
<servlet-name>s1</servlet-name>
<servlet-class>com.Servlet.myPack.PrimeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s1</servlet-name>
<url-pattern>/primeServlet</url-pattern>
</servlet-mapping>
</web-app>
1. Designing in Servlet is difficult and slows down the
application.
2. Writing complex business logic makes the application difficult
to understand.
3. You need a java runtime environment on the server to run
servlet.
4. Developing web application in servlet is unproductive i,e, a
lot of code need to be written even for simple tasks.
Drawbacks of Servlet
 JSP(Java Server Page) is the extension of servlet which facilitates productive
development of dynamic web application in java.
 JSP simplifies the development of dynamic web by facilitating the
embedding of request processing logic into the HTML itself with the help of
special tags.
 Each JSP page is automatically translated into servlet by the server at
runtime.
 Using JSP we can collect input from users, through web page forms, present
records from a database or another source and create web page
dynamically.
 JSP tags can be used for variety of purposes such as retrieving information
from a database or registering user preferences, accessing javabeans
components, passing control between pages and sharing information
between requests, pages etc.
Introduction of JSP
1. JSP increases the productivity of the application programmers
as they are only required to provide the processing logic. All
the repetitive tasks such as defining classes & request
processing methods, and writing static HTML contents to the
output stream, are automated.
2. Maintenance is simplified. Static HTML contents or request
processing logic can be changed on the fly because of the
automated translation.
Advantages of JSP over Servlet
 Performance is significantly better because JSP allows embedding Dynamic
Elements in HTML Pages itself instead of having a separate CGI files.
 JSP are always compiled before it's processed by the server unlike CGI/Perl
which requires the server to load an interpreter and the target script each
time the page is requested.
 Java Server Pages are built on top of the Java Servlets API, so like Servlets,
JSP also has access to all the powerful Enterprise Java APIs, including JDBC,
JNDI, EJB, JAXP etc.
 JSP pages can be used in combination with servlets that handle the business
logic, the model supported by Java servlet template engines.
Why Jsp?

1. Client first sends request for a JSP page
2. Using a Jsp page a servlet is generated by server component. This servlet
contains the request processing logic of the JSP and auto generated
statement to write the static HTML content to the output stream.
3. The translated servlet is compiled.
4. An object of the generated servlet class is created and initialized.
5. Request processing method _jspService(request,response)is invoked on the
servlet object.
6. Contents dynamically generated by _jspService(request,response)method
are sent as response to the client.
Working of JSP
Jsp life cycle is defined by JspPage and HttpJspPage interfaces
Javax.servlet.jsp package contains classes and interfaces of JSP API.
Main classes and interfaces of JSP API are:
1. JspPage:It extends Servlet interface and adds following JSP life cycle
methods:
 jspInit():This method is provided to define initialization operations of
JSP. Syntax:
public void jspInit();
 jspDestroy(): This method is provided to define clean up operations
of the jsp. Syntax:
public void JspDestroy();
2. HttpJspPage: It extends Jsp page interface and provides following life
cycle method:
JSP Life Cycle

3. _jspService(): This method is provided to define request
processing logic of the JSP. Syntax
public void _jspService(HttpServleRequest request,
HttpServletResponse response )throws ServletException,
IOException;
Jsp supports following types of tags:
1. Scriptlet.
2. Declaration.
3. Expression.
4. Directives.
5. Actions
Tags supported by Jsp

1. Scriptlet is the main tag of JSP. It is used to add request processing logic to
a JSP page. A JSP page may contain any number of scriptlet tags.Syntax
<%requestprocessing logic%>
At the time of translation scriptlet contents are used by the server for defining
body of _JspService method.
Within Scriptlet following implicit objects are made available to a Jsp
programmer.
 Out JspWriter.
 Request HttpServletRequest object which contains
request parameters and attributes
 Response Is HttpServletResponse object.
 Config Is ServletConfig object of the servlet.
 Session Is HttpSession object of the user.
 Application Is the ServletContext object of the application
 Page is the current servlet object of the jsp.
 pageContext Is an object of type PageContext. It acts as a container of a
all the other servlet and JSP API objects which participate
request processing.
 Exception is an optional object which is available only when exc. ocr

An Example demonstrating use of Scriptlet tag:
<form method="post" action="adder.jsp">
First No: <input type="text" name="num1"><br/>
Second No: <input type="text" name="num2"><br/>
<input type="submit" value="add"> </form>
<% int a=Integer.parseInt(request.getParameter("num1"));
int b=Integer.parseInt(request.getParameter("num2"));
int c=a+b;
out.println("sum is: "+c); %>
with this example we have understood the simplication provided, Here
no class or method is defined, no object is declared, no content type is set, no
web.xml file is required

2. Declaration tag in Jsp facilitate data members and method definition in the
auto generated servlet.. Main use of this tag is the overriding of jspInit() and
jspDestroy() methods.
<%! Data members and method definition%>
An example demonstrating the use of Declaration tag
<form method="post" action="hello.jsp">
Name <input type="text" name="name"><br/>
<input type="submit" value="submit">
</form>
<%!
private String userName;
Public String sayHello(){
Return “Hello”+userName;
}
Public void jspInit()
{
System.out.println(“hello.jsp is initialized”);
}
%>

3. Expression tag in jsp has two uses:
1. It is used to write the value of an expression to the output
stream.
2. It is used to assign the value of variables and expression to the
attributes of HTML elements.
syntax: <%=variable or expression%>
4. Action Tags in Jsp facilitate automation of common operations
such as creation of objects, setting object’s properties, writing
object’s property values to the output stream, including the
contents of a component to the reponse of current request and
forwarding request to another component etc. An action tag has
following syntax:
<jsp:actionName attribute=value…/>

Action Tags in Jsp facilitates automation of common operations such as
creation of objects, setting object’s properties, writing object properties, writing
objects’s property value to the output stream, including contents of a
component to the response of current request and forwarding request to
another component etc.
Commonly used action tags of Jsp:
<jsp:include />: used to include the contents of specified page to the response
of current request.
<jsp:forward />: used to forward request to the specified page.
<jsp:useBean/>: used to create a Bean Object and save it in a scope.
<jsp:setProperty/>: used to set property of java Bean object.
<jsp:getProperty/>:used to write the value of java Bean object to the output
stream.
<jsp:param/>: it is used to define parameters to be provided to the included or
forwarded page.
A directive in JSP, represents an instruction to the translator to modify the
structure of the auto generated servlet at the time of translation on behalf of the
programmer. As we know for each JSP, a servlet class is autogenerate.
Sometimes modifications are required in this servlet e,g. Some extra packages
need to be imported in it or it need to be inherited from a use defined class, or
exception need to be managed in some specific way.Syntax:
%@directiveName attribute=“value..”%
Information to the translator is provided with the help of attributes.
JSP suports following three directives:
Page
Include and
taglib
Directives

 Include directive in JSP, is used by application programmers to
get the contents of a page included to the current JSP at the
time of translation.
<%@include file=“url of the component to be included ”%>
 JSP page directive is used by the programmer to get the
structure of the auto generated servlet modified according to
their requirements.
<%@page attributeName=“value”%>
commonly used attributes:
 import <%@page import=“packageName”%>
 Extends <%page extends=“className”%>
 ContentType<%@page contentType=“MIMEType”%>
 Session <%@page session=“false”%>
 isErrorPage<%@page isErrorPage=“true”%>
 errorPage<%page errorPage=“URL of errorHandlerPage”%>

thank you……
MORE TO COME

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Ajax Ppt 1
Ajax Ppt 1Ajax Ppt 1
Ajax Ppt 1
 
virtual hosting and configuration
virtual hosting and configurationvirtual hosting and configuration
virtual hosting and configuration
 
Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Language
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Active browser web page
Active browser web pageActive browser web page
Active browser web page
 
Servlets
ServletsServlets
Servlets
 
PHP Cookies and Sessions
PHP Cookies and SessionsPHP Cookies and Sessions
PHP Cookies and Sessions
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Http request and http response
Http request and http responseHttp request and http response
Http request and http response
 
Applets
AppletsApplets
Applets
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
 
Android intents
Android intentsAndroid intents
Android intents
 
java Features
java Featuresjava Features
java Features
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in java
 
Enterprise java unit-2_chapter-3
Enterprise  java unit-2_chapter-3Enterprise  java unit-2_chapter-3
Enterprise java unit-2_chapter-3
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
servlet in java
servlet in javaservlet in java
servlet in java
 
Java applets
Java appletsJava applets
Java applets
 
HTTP request and response
HTTP request and responseHTTP request and response
HTTP request and response
 

Andere mochten auch

Server side programming
Server side programmingServer side programming
Server side programmingSayed Ahmed
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postvamsi krishna
 
Server Side Programming
Server Side Programming Server Side Programming
Server Side Programming Zac Gordon
 
Introduction to Node.js: perspectives from a Drupal dev
Introduction to Node.js: perspectives from a Drupal devIntroduction to Node.js: perspectives from a Drupal dev
Introduction to Node.js: perspectives from a Drupal devmcantelon
 
Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming  Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming Tom Croucher
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsVikash Singh
 
Relational databases vs Non-relational databases
Relational databases vs Non-relational databasesRelational databases vs Non-relational databases
Relational databases vs Non-relational databasesJames Serra
 
Comet with node.js and V8
Comet with node.js and V8Comet with node.js and V8
Comet with node.js and V8amix3k
 
Node.js and The Internet of Things
Node.js and The Internet of ThingsNode.js and The Internet of Things
Node.js and The Internet of ThingsLosant
 

Andere mochten auch (10)

Server side programming
Server side programmingServer side programming
Server side programming
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
Server Side Programming
Server Side Programming Server Side Programming
Server Side Programming
 
Introduction to Node.js: perspectives from a Drupal dev
Introduction to Node.js: perspectives from a Drupal devIntroduction to Node.js: perspectives from a Drupal dev
Introduction to Node.js: perspectives from a Drupal dev
 
Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming  Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming
 
Introduction Node.js
Introduction Node.jsIntroduction Node.js
Introduction Node.js
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Relational databases vs Non-relational databases
Relational databases vs Non-relational databasesRelational databases vs Non-relational databases
Relational databases vs Non-relational databases
 
Comet with node.js and V8
Comet with node.js and V8Comet with node.js and V8
Comet with node.js and V8
 
Node.js and The Internet of Things
Node.js and The Internet of ThingsNode.js and The Internet of Things
Node.js and The Internet of Things
 

Ähnlich wie Server side programming

Ähnlich wie Server side programming (20)

Ecom 1
Ecom 1Ecom 1
Ecom 1
 
Servlet session 1
Servlet   session 1Servlet   session 1
Servlet session 1
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technology
 
Servlet.pptx
Servlet.pptxServlet.pptx
Servlet.pptx
 
Servlet.pptx
Servlet.pptxServlet.pptx
Servlet.pptx
 
Presentation on java servlets
Presentation on java servletsPresentation on java servlets
Presentation on java servlets
 
Servlet by Rj
Servlet by RjServlet by Rj
Servlet by Rj
 
Programming Server side with Sevlet
 Programming Server side with Sevlet  Programming Server side with Sevlet
Programming Server side with Sevlet
 
Java servlets
Java servletsJava servlets
Java servlets
 
Servlets
ServletsServlets
Servlets
 
Java Servlet
Java ServletJava Servlet
Java Servlet
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jsp
 
Unit5 servlets
Unit5 servletsUnit5 servlets
Unit5 servlets
 
Ppt for Online music store
Ppt for Online music storePpt for Online music store
Ppt for Online music store
 
It and ej
It and ejIt and ej
It and ej
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
 
Intorduction to struts
Intorduction to strutsIntorduction to struts
Intorduction to struts
 
WEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptxWEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptx
 
AJppt.pptx
AJppt.pptxAJppt.pptx
AJppt.pptx
 

Kürzlich hochgeladen

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answersdalebeck957
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 

Kürzlich hochgeladen (20)

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 

Server side programming

  • 1. Javed Ahmed Coleta Software solutions pvt. Ltd.
  • 2. 1. In IT term a Server is a computer program that provides services to other computer programs(or Users ) in the same or other computers. 2. The computer in which server program runs is frequently referred as Server(though it may be used for other purposes as well). 3. In a client server programming model a server is a program that awaits and fulfills requests from client programs in the same or other computers. A given application in a computer may function as a client which requests for services from other programs. 4. Specific to the web, a web server is a computer program(housed in a computer) that serves requested HTML pages or files. A web client is the requesting program associated with the user. The web browser in your computer is a client that requests HTML files from Web server. What is Server
  • 3.  A web site is a collection of web pages which are stored on a web server and can be accessed from any where using a web browser. The purpose of a web site is to share information over the network. Web sites can be of two types:  Static web sites  Dynamic web sites In a static web site, the information which is presented to the end user, remain available on the server usually in the form of HTML pages. When a user sends a request to a page, contents of the page are sent by the server as response. In a dynamic web site, server has programs which are executed when a request is submitted by clients, these programs process requests and generate HTML contents which are sent by the server as response to the client. What is static and Dynamic Web Site
  • 4. 1. Client side programming generally refers to the class of programs on the web that are executed client side by the user’s web browser OR by client side we refer to code that is executed directly on the device that the user is using. 2. Upon request, the necessary files are sent to the user’s computer by the web server (or server) on which they reside. 3. The user’s web browser executes the script and then displays the document. 4. Client side programming language example include javascript. disadvantage:  By viewing the file that contains the script users may be able to see the source code. What is Client side Side Programming
  • 5. 1. Server side programming generally refers to the class of programs that are written to be executed on the Server. 2. A request is generated to execute some program stored on the server. 3. Server in turn serves the request i,e, executes the requested code piece on server and returns response. 4. Some of the languages used for building Server side application are: Java, Php, Python, Ruby, etc. Advantage over Client Side Programming:  The User cannot see the source code and may not be even aware that a script is executed. What is Server Side Programming
  • 6. 1. In early days of the web, server side programming was almost exclusively performed by using combination of C programs, Perl scripts and Shell scripts using the common gateway interface(CGI). 2. CGI is a protocol which provides standard rules for server to invoke programs, to provide requested data to them and to receive the processed result from them. Drawbacks of CGI based web applications:  .For each request a process is started by the server to execute CGI script, Process creation and destruction results in extra overhead than actual processing time.  If number of requests increase, it takes more time for sending response  CGI scripts were platform dependent i,e, if the web application is to be deployed from windows to Linux server or vice versa CGI script need to be recompiled for the target platform. History of Server side Programming
  • 7.  To remove the drawbacks of CGI protocol, Sun microsystem in 1988 introduced the Servlet API. 1. To remove the overhead of process creation and destruction, a thread based request processing model is provided by servlet. 2. By facilitating the development of web based application in java, problem of platform dependency is removed Introduction of Servlets
  • 8. Servlet term is used with two different meanings in two different contexts, 1. In the broader context it represents an API which facilitates development of dynamic web applications 2. In the narrow context it represents a java class which is defined using this API for processing requests in a web application. This component is responsible for processing requests in web application. javax.servlet.Servlet is the main interface of the API, it provides methods which define initialization, processing and destruction phase of a Servlet. These methods are called servlet life cycle methods. What is Servlet
  • 9. Various life cycle methods of servlet are discussed below: 1. init(): This method defines Initialization. This method is invoked only once just afte servlet object is created. public void init(ServletConfig config); 2. Service(): This method is invoked by the server each time a request is received for the servlet.It is used by the servlet for processing requests. public void service(ServletRequest request, ServletResponse response)throws ServletException, IOException. 3. Destroy():This method is invoked by the server only once just after the servlet in unloaded. It can be used by the application programmer for defining cleanup operations. public void destroy(); Life cycle methods of a Servlet
  • 10. A servlet program can be created by three ways: i. By implementing a servlet interface. ii. By inheriting GenericServlet class. iii. By inheriting HttpServlet class. Server side Program to check whether a number is Prime or not? Presentation logic: <form action=“primeServlet” method=“post”> <center> Enter Number<Input type=“Text” name=“num”> <Input type=“submit” value=“check”></center> </form> Skeleton of a Servlet program
  • 11.  Business logic: PrimeServlet.java import javax.Servlet.*; import javax.Servlet.http.*; import java.io.*; class PrimeServlet extends HttpServlet{ public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException IOException { response.setContentType(“text/html”) ; PrintWriter out=response.getWriter(); //request data is read int p=Integer.parseInt(request.getParameter); //Business logic is defined int d=2; while(num%d!=0) d++; if(num==d) Out.println(“number is prime”); else out.println(“number is not prime”); out.close } }
  • 12.  Deployment Descriptor(Web.xml): A web application’s deployment descriptor describes the classes, resources and configuration of the application and how the web server uses them to serve web requests. When the web server receives a request for the application, it uses deployment descriptor to map the URL of the request to code that ought to handle the request. The deployment descriptor is a file named web.xml. Web.xml for our program is as <web-app> <servlet> <servlet-name>s1</servlet-name> <servlet-class>com.Servlet.myPack.PrimeServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>s1</servlet-name> <url-pattern>/primeServlet</url-pattern> </servlet-mapping> </web-app>
  • 13. 1. Designing in Servlet is difficult and slows down the application. 2. Writing complex business logic makes the application difficult to understand. 3. You need a java runtime environment on the server to run servlet. 4. Developing web application in servlet is unproductive i,e, a lot of code need to be written even for simple tasks. Drawbacks of Servlet
  • 14.  JSP(Java Server Page) is the extension of servlet which facilitates productive development of dynamic web application in java.  JSP simplifies the development of dynamic web by facilitating the embedding of request processing logic into the HTML itself with the help of special tags.  Each JSP page is automatically translated into servlet by the server at runtime.  Using JSP we can collect input from users, through web page forms, present records from a database or another source and create web page dynamically.  JSP tags can be used for variety of purposes such as retrieving information from a database or registering user preferences, accessing javabeans components, passing control between pages and sharing information between requests, pages etc. Introduction of JSP
  • 15. 1. JSP increases the productivity of the application programmers as they are only required to provide the processing logic. All the repetitive tasks such as defining classes & request processing methods, and writing static HTML contents to the output stream, are automated. 2. Maintenance is simplified. Static HTML contents or request processing logic can be changed on the fly because of the automated translation. Advantages of JSP over Servlet
  • 16.  Performance is significantly better because JSP allows embedding Dynamic Elements in HTML Pages itself instead of having a separate CGI files.  JSP are always compiled before it's processed by the server unlike CGI/Perl which requires the server to load an interpreter and the target script each time the page is requested.  Java Server Pages are built on top of the Java Servlets API, so like Servlets, JSP also has access to all the powerful Enterprise Java APIs, including JDBC, JNDI, EJB, JAXP etc.  JSP pages can be used in combination with servlets that handle the business logic, the model supported by Java servlet template engines. Why Jsp?
  • 17.
  • 18. 1. Client first sends request for a JSP page 2. Using a Jsp page a servlet is generated by server component. This servlet contains the request processing logic of the JSP and auto generated statement to write the static HTML content to the output stream. 3. The translated servlet is compiled. 4. An object of the generated servlet class is created and initialized. 5. Request processing method _jspService(request,response)is invoked on the servlet object. 6. Contents dynamically generated by _jspService(request,response)method are sent as response to the client. Working of JSP
  • 19. Jsp life cycle is defined by JspPage and HttpJspPage interfaces Javax.servlet.jsp package contains classes and interfaces of JSP API. Main classes and interfaces of JSP API are: 1. JspPage:It extends Servlet interface and adds following JSP life cycle methods:  jspInit():This method is provided to define initialization operations of JSP. Syntax: public void jspInit();  jspDestroy(): This method is provided to define clean up operations of the jsp. Syntax: public void JspDestroy(); 2. HttpJspPage: It extends Jsp page interface and provides following life cycle method: JSP Life Cycle
  • 20.  3. _jspService(): This method is provided to define request processing logic of the JSP. Syntax public void _jspService(HttpServleRequest request, HttpServletResponse response )throws ServletException, IOException;
  • 21. Jsp supports following types of tags: 1. Scriptlet. 2. Declaration. 3. Expression. 4. Directives. 5. Actions Tags supported by Jsp
  • 22.  1. Scriptlet is the main tag of JSP. It is used to add request processing logic to a JSP page. A JSP page may contain any number of scriptlet tags.Syntax <%requestprocessing logic%> At the time of translation scriptlet contents are used by the server for defining body of _JspService method. Within Scriptlet following implicit objects are made available to a Jsp programmer.  Out JspWriter.  Request HttpServletRequest object which contains request parameters and attributes  Response Is HttpServletResponse object.  Config Is ServletConfig object of the servlet.  Session Is HttpSession object of the user.  Application Is the ServletContext object of the application  Page is the current servlet object of the jsp.  pageContext Is an object of type PageContext. It acts as a container of a all the other servlet and JSP API objects which participate request processing.  Exception is an optional object which is available only when exc. ocr
  • 23.  An Example demonstrating use of Scriptlet tag: <form method="post" action="adder.jsp"> First No: <input type="text" name="num1"><br/> Second No: <input type="text" name="num2"><br/> <input type="submit" value="add"> </form> <% int a=Integer.parseInt(request.getParameter("num1")); int b=Integer.parseInt(request.getParameter("num2")); int c=a+b; out.println("sum is: "+c); %> with this example we have understood the simplication provided, Here no class or method is defined, no object is declared, no content type is set, no web.xml file is required
  • 24.  2. Declaration tag in Jsp facilitate data members and method definition in the auto generated servlet.. Main use of this tag is the overriding of jspInit() and jspDestroy() methods. <%! Data members and method definition%> An example demonstrating the use of Declaration tag <form method="post" action="hello.jsp"> Name <input type="text" name="name"><br/> <input type="submit" value="submit"> </form> <%! private String userName; Public String sayHello(){ Return “Hello”+userName; } Public void jspInit() { System.out.println(“hello.jsp is initialized”); } %>
  • 25.  3. Expression tag in jsp has two uses: 1. It is used to write the value of an expression to the output stream. 2. It is used to assign the value of variables and expression to the attributes of HTML elements. syntax: <%=variable or expression%> 4. Action Tags in Jsp facilitate automation of common operations such as creation of objects, setting object’s properties, writing object’s property values to the output stream, including the contents of a component to the reponse of current request and forwarding request to another component etc. An action tag has following syntax: <jsp:actionName attribute=value…/>
  • 26.  Action Tags in Jsp facilitates automation of common operations such as creation of objects, setting object’s properties, writing object properties, writing objects’s property value to the output stream, including contents of a component to the response of current request and forwarding request to another component etc. Commonly used action tags of Jsp: <jsp:include />: used to include the contents of specified page to the response of current request. <jsp:forward />: used to forward request to the specified page. <jsp:useBean/>: used to create a Bean Object and save it in a scope. <jsp:setProperty/>: used to set property of java Bean object. <jsp:getProperty/>:used to write the value of java Bean object to the output stream. <jsp:param/>: it is used to define parameters to be provided to the included or forwarded page.
  • 27. A directive in JSP, represents an instruction to the translator to modify the structure of the auto generated servlet at the time of translation on behalf of the programmer. As we know for each JSP, a servlet class is autogenerate. Sometimes modifications are required in this servlet e,g. Some extra packages need to be imported in it or it need to be inherited from a use defined class, or exception need to be managed in some specific way.Syntax: %@directiveName attribute=“value..”% Information to the translator is provided with the help of attributes. JSP suports following three directives: Page Include and taglib Directives
  • 28.   Include directive in JSP, is used by application programmers to get the contents of a page included to the current JSP at the time of translation. <%@include file=“url of the component to be included ”%>  JSP page directive is used by the programmer to get the structure of the auto generated servlet modified according to their requirements. <%@page attributeName=“value”%> commonly used attributes:  import <%@page import=“packageName”%>  Extends <%page extends=“className”%>  ContentType<%@page contentType=“MIMEType”%>  Session <%@page session=“false”%>  isErrorPage<%@page isErrorPage=“true”%>  errorPage<%page errorPage=“URL of errorHandlerPage”%>