SlideShare a Scribd company logo
1 of 37
Server Side Web Programming
Web Information Systems 2015
Preliminaries
• HTML
– Standard mark up language to create web pages
• CSS
– Style sheets for web pages
• Javascript
– Client side programming
• Java, Perl, Python, Php
What are web servers
• Hardware or software
– Helps deliver the web content that can be
accessed through internet (Wikipedia)
Web Server
File System
Request
Response
Read Static
Files
knoesis.org
(Web Server)
http://knoesis.org/amit
Web Servers
• History
– CERN httpd
• Apache – 60%
– Open source
– Linux, Windows, Mac
• IIS -- Internet Information Service
– Microsoft
– Windows
• Mostly installed automatically
• Generally run on Windows Server edition
• High Performance
• Nginx
• Lighttpd
– Both usually used as forward and reverse Proxy
Apache Download
• Packages
– LAMP -- http://www.lamphowto.com/
– WAMP -- http://www.wampserver.com/en/
– MAMP -- http://sawmac.com/mamp/
• Apache Installation
– Ubuntu – sudo apt-get install apache2/Synaptic
Package manager
– Windows and Mac – Download Apache
• http://httpd.apache.org/download.cgi
Web servers
• Delivers static web pages
• Don’t we see a lot of dynamic pages on the
web?
– Weather reports
– Date time changes on web sites
– User information updates
Friends Likes
and Comments
Friends Updates
Facebook
Forms with
Values to input
Dynamic Web Pages
Web Server
Script
Request
Response
DB
Email already registered
Frontend
• Data has to be sent to the server and response
has to displayed.
• How do we send data to the server
– HTTP methods
– Javascript
• Ajax
• JSON, XML
– HTML Forms
HTTP Methods
• Get
– Data encoded in the URL
– For idempotent data
• No changes are done except on the users screen
• Basically for retrieving data
– http://knoesis.org
/<pagename>?<param1>=<value1>&<param2>=<value2>…
– Param and value is the data sent.
• Post
– Data goes with the message body
– Changes the state
• Adds or deletes data at the server
– Cannot backtrack the history because the URL will be the same
HTML Forms
• Pass Data to the server
– Text fields, check box, radio button, submit button
etc.
• For More
– http://www.w3.org/TR/html401/interact/forms.ht
ml
Example
<BODY>
<FORM action=”destination script/url”
method="post">
<INPUT type=“submit” value=" submit” >
</FORM>
</BODY>
Technologies at the Server Side
Technologies
• CGI
– Common Gateway interface
• Servlets – Need to know Java
• Php
– Hypertext Preprocessor
CGI
• Common Gateway Interface (CGI)
– Runs a scripts for every request – New process
• Drawbacks
– Limited Functionality
– Scalability Issues
Servlets
• Java Programming Class used to extend the
capabilities of server that host applications
accessed via a request-response programming
model.
• Java Technology’s answer to CGI.
• Advantages of Java?
• Needs a servlet container
Servlet Container
• Component of a web server that interacts
with the Servlets
– Manages the Lifecycle of a servlet
– Mapping URL to appropriate servlets
– Security, concurrency, deployment etc .
• Examples
– Apache Tomcat (opensource)
– Jboss (opensource)
– IBM Websphere
Tomcat Installation
• Follow
– http://tomcat.apache.org/tomcat-7.0-
doc/appdev/installation.html
• Eclipse + Tomcat
– http://www.coreservlets.com/Apache-Tomcat-
Tutorial/tomcat-7-with-eclipse.html
Plain HTML Text Servlet
package testPackage; // Always use packages.
import java.io.*;
import javax.servlet.*;
import javax.servlet.annotation.*;
import javax.servlet.http.*;
@WebServlet("/hello")
public class HelloWorld extends HttpServlet {
@Override
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("Hello World");
}
}
Interpreting the Servlet
• @WebServlet("/hello”)
– This is the URL relative to the app name
– http://knoesis.org:8080/hello
• doGet
– Code for an HTTP GET request. doPost also common.
• HttpServletRequest, HttpServletResponse
– Contains anything that comes from the browser
– Send data back to the browser
• @Override
Lets see how to generate a simple
HTML
<!DOCTYPE html>
<html lang="en">
<head>
..
</head>
<body>
...
</body>
</html>
Servlet that generates HTML
@WebServlet("/test1")
public class TestServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println ("<!DOCTYPE html>n"
+"<html>n" +
"<head><title>A Test Servlet</title></head>n" +
"<body bgcolor="#fdf5e6">n" +
"<h1>Test</h1>n" +
"<p>Simple servlet for testing.</p>n" +
"</body></html>");
}
}
Modifying web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4”... >
<servlet>
<servlet-name>TestServlet</servlet-name>
<display-name>Print Text</display-name>
<servlet-class>testPackage.TestServlet</servlet-class>
<init-param>
<param-name> param1 </param-name>
<param-value> value1 </param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/test2</url-pattern>
</servlet-mapping>
</web-app>
Passing
parameters
Custom URLs
Php
• General purpose server-side scripting
language originally designed for web
development to produce dynamic web pages
• Hypertext Preprocessor
• Dynamically Typed Language
Php – Hello World
• Embed PHP script into an HTML file
• Upload the file onto a Web server using
extension .php (Apache)
• Embed using the following delimiters
– < ? ... ? >
– <?php ... ?>
– <script language=”php”> ... </script>
– <% ... %>
Php – Hello World
<html>
<body>
<?php
echo "Hello World";
?>
</body>
</html>
Delimiters – seperates PHP
to non-PHP code
<?php ?>
Php Applications
• Wide range of applications (similar to CGI)
– Forms handling, etc.
• Wide range of PHP libraries
– Network connectivity (e.g. access FTP, IMAP, SMTP, etc
– Database connectivity (e.g. MySQL, dBase, Oracle,
etc.)
– XML/XSLT manipulation
– Image manipulation
GET – POST
• Access form fields through PHP array
– $HTTP_POST_VARS for POST method
– $HTTP_GET_VARS for GET method
– $_POST for POST method (>=PHP4.1.0)
– $_GET for GET method (>=PHP4.1.0)
$name = $_POST["name"];
$name = $_GET["name"];
• Similar to request.getParameter(“name”) in
doPost/doGet in Servlets.
Prints even numbers until
“max”
<html>
<head><title>A Test Php</title></head>
<body bgcolor="#fdf5e6">
<p> <ul>
<?php
$maximum = $_GET["max"];
for($i=0; $i<=$maximum ; $i=$i+2){
echo "<li>$i</li>";
}
?>
</ul>
</p>
</body>
</html>
References
• Common
– http://coronet.iicm.edu/lectures/mmis/material/s
lides_serverside_main.pdf
• Servlets
– http://courses.coreservlets.com/Course-
Materials/pdf/csajsp2/02-Servlet-Basics.pdf
• Php
– http://www.php.net/
– http://www.w3schools.com/php/
Friends Likes and
Comments
Friends Updates
Partial Changes
JSON, XML Handling
• Change the content type
• Construct a Json/XML
• Pass it as it is done for plain text or html
• More about this in the next class.
• Might be a part of the assignment
CGI/Perl
• 1987 – Before the web
• Text manipulation language
• CGI – Common Gateway interface
– Can run any language
– Commonly perl
• Advantages
– Mature language over a decade of history
– Free and most os support perl
– Vast network of perl developers
• Disadvantage
– Scalability
– Optimized for unix platform
– Different ways of doing the same thing hence not easy to learn

More Related Content

What's hot (20)

Presentation of bootstrap
Presentation of bootstrapPresentation of bootstrap
Presentation of bootstrap
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
ASP.NET Basics
ASP.NET Basics ASP.NET Basics
ASP.NET Basics
 
Spring Security 5
Spring Security 5Spring Security 5
Spring Security 5
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web API
 
Introduction of Html/css/js
Introduction of Html/css/jsIntroduction of Html/css/js
Introduction of Html/css/js
 
Bootstrap
BootstrapBootstrap
Bootstrap
 
WSDL
WSDLWSDL
WSDL
 
Bootstrap Framework
Bootstrap Framework Bootstrap Framework
Bootstrap Framework
 
Web container and Apache Tomcat
Web container and Apache TomcatWeb container and Apache Tomcat
Web container and Apache Tomcat
 
Web application framework
Web application frameworkWeb application framework
Web application framework
 
Architecture: Microservices
Architecture: MicroservicesArchitecture: Microservices
Architecture: Microservices
 
Web api
Web apiWeb api
Web api
 
Api Gateway
Api GatewayApi Gateway
Api Gateway
 
Webservices
WebservicesWebservices
Webservices
 
Asp.net.
Asp.net.Asp.net.
Asp.net.
 
Web Application Introduction
Web Application  IntroductionWeb Application  Introduction
Web Application Introduction
 
Feature and Future of ASP.NET
Feature and Future of ASP.NETFeature and Future of ASP.NET
Feature and Future of ASP.NET
 
Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jsp
 

Similar to Lecture 7: Server side programming

Apache HTTPd Server 2.2 Presentation
Apache HTTPd Server 2.2 PresentationApache HTTPd Server 2.2 Presentation
Apache HTTPd Server 2.2 Presentationultimatetux
 
05.m3 cms list-ofwebserver
05.m3 cms list-ofwebserver05.m3 cms list-ofwebserver
05.m3 cms list-ofwebservertarensi
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postvamsitricks
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postvamsi krishna
 
4th Lecture: JSP and such
4th Lecture:  JSP and such4th Lecture:  JSP and such
4th Lecture: JSP and suchManolis Vavalis
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postvamsitricks
 
Securing Your Webserver By Pradeep Sharma
Securing Your Webserver By Pradeep SharmaSecuring Your Webserver By Pradeep Sharma
Securing Your Webserver By Pradeep SharmaOSSCube
 
phpwebdev.ppt
phpwebdev.pptphpwebdev.ppt
phpwebdev.pptrawaccess
 
Website designing company_in_delhi_phpwebdevelopment
Website designing company_in_delhi_phpwebdevelopmentWebsite designing company_in_delhi_phpwebdevelopment
Website designing company_in_delhi_phpwebdevelopmentCss Founder
 
Web technologies lesson 1
Web technologies   lesson 1Web technologies   lesson 1
Web technologies lesson 1nhepner
 
Preparing for SRE Interviews
Preparing for SRE InterviewsPreparing for SRE Interviews
Preparing for SRE InterviewsShivam Mitra
 
Indroduction to Web Application
Indroduction to Web ApplicationIndroduction to Web Application
Indroduction to Web Applicationtorny10
 
6 3 tier architecture php
6 3 tier architecture php6 3 tier architecture php
6 3 tier architecture phpcefour
 
An Introduction to Websphere sMash for PHP Programmers
An Introduction to Websphere sMash for PHP ProgrammersAn Introduction to Websphere sMash for PHP Programmers
An Introduction to Websphere sMash for PHP Programmersjphl
 
Introduction_Web_Technologies
Introduction_Web_TechnologiesIntroduction_Web_Technologies
Introduction_Web_TechnologiesDeepak Raj
 

Similar to Lecture 7: Server side programming (20)

Apache HTTPd Server 2.2 Presentation
Apache HTTPd Server 2.2 PresentationApache HTTPd Server 2.2 Presentation
Apache HTTPd Server 2.2 Presentation
 
05.m3 cms list-ofwebserver
05.m3 cms list-ofwebserver05.m3 cms list-ofwebserver
05.m3 cms list-ofwebserver
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
4th Lecture: JSP and such
4th Lecture:  JSP and such4th Lecture:  JSP and such
4th Lecture: JSP and such
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
Securing Your Webserver By Pradeep Sharma
Securing Your Webserver By Pradeep SharmaSecuring Your Webserver By Pradeep Sharma
Securing Your Webserver By Pradeep Sharma
 
phpwebdev.ppt
phpwebdev.pptphpwebdev.ppt
phpwebdev.ppt
 
Website designing company_in_delhi_phpwebdevelopment
Website designing company_in_delhi_phpwebdevelopmentWebsite designing company_in_delhi_phpwebdevelopment
Website designing company_in_delhi_phpwebdevelopment
 
Web technologies lesson 1
Web technologies   lesson 1Web technologies   lesson 1
Web technologies lesson 1
 
Preparing for SRE Interviews
Preparing for SRE InterviewsPreparing for SRE Interviews
Preparing for SRE Interviews
 
unit1 part 1 sem4 php.docx
unit1 part 1 sem4 php.docxunit1 part 1 sem4 php.docx
unit1 part 1 sem4 php.docx
 
Indroduction to Web Application
Indroduction to Web ApplicationIndroduction to Web Application
Indroduction to Web Application
 
Php reports sumit
Php reports sumitPhp reports sumit
Php reports sumit
 
Php
PhpPhp
Php
 
Be faster then rabbits
Be faster then rabbitsBe faster then rabbits
Be faster then rabbits
 
6 3 tier architecture php
6 3 tier architecture php6 3 tier architecture php
6 3 tier architecture php
 
An Introduction to Websphere sMash for PHP Programmers
An Introduction to Websphere sMash for PHP ProgrammersAn Introduction to Websphere sMash for PHP Programmers
An Introduction to Websphere sMash for PHP Programmers
 
Introduction_Web_Technologies
Introduction_Web_TechnologiesIntroduction_Web_Technologies
Introduction_Web_Technologies
 
PHP MySQL Workshop - facehook
PHP MySQL Workshop - facehookPHP MySQL Workshop - facehook
PHP MySQL Workshop - facehook
 

Recently uploaded

Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 

Recently uploaded (20)

Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 

Lecture 7: Server side programming

  • 1. Server Side Web Programming Web Information Systems 2015
  • 2. Preliminaries • HTML – Standard mark up language to create web pages • CSS – Style sheets for web pages • Javascript – Client side programming • Java, Perl, Python, Php
  • 3. What are web servers • Hardware or software – Helps deliver the web content that can be accessed through internet (Wikipedia) Web Server File System Request Response Read Static Files
  • 5. Web Servers • History – CERN httpd • Apache – 60% – Open source – Linux, Windows, Mac • IIS -- Internet Information Service – Microsoft – Windows • Mostly installed automatically • Generally run on Windows Server edition • High Performance • Nginx • Lighttpd – Both usually used as forward and reverse Proxy
  • 6. Apache Download • Packages – LAMP -- http://www.lamphowto.com/ – WAMP -- http://www.wampserver.com/en/ – MAMP -- http://sawmac.com/mamp/ • Apache Installation – Ubuntu – sudo apt-get install apache2/Synaptic Package manager – Windows and Mac – Download Apache • http://httpd.apache.org/download.cgi
  • 7. Web servers • Delivers static web pages • Don’t we see a lot of dynamic pages on the web? – Weather reports – Date time changes on web sites – User information updates
  • 10. Dynamic Web Pages Web Server Script Request Response DB
  • 12. Frontend • Data has to be sent to the server and response has to displayed. • How do we send data to the server – HTTP methods – Javascript • Ajax • JSON, XML – HTML Forms
  • 13. HTTP Methods • Get – Data encoded in the URL – For idempotent data • No changes are done except on the users screen • Basically for retrieving data – http://knoesis.org /<pagename>?<param1>=<value1>&<param2>=<value2>… – Param and value is the data sent. • Post – Data goes with the message body – Changes the state • Adds or deletes data at the server – Cannot backtrack the history because the URL will be the same
  • 14. HTML Forms • Pass Data to the server – Text fields, check box, radio button, submit button etc. • For More – http://www.w3.org/TR/html401/interact/forms.ht ml
  • 15. Example <BODY> <FORM action=”destination script/url” method="post"> <INPUT type=“submit” value=" submit” > </FORM> </BODY>
  • 16. Technologies at the Server Side
  • 17. Technologies • CGI – Common Gateway interface • Servlets – Need to know Java • Php – Hypertext Preprocessor
  • 18. CGI • Common Gateway Interface (CGI) – Runs a scripts for every request – New process • Drawbacks – Limited Functionality – Scalability Issues
  • 19. Servlets • Java Programming Class used to extend the capabilities of server that host applications accessed via a request-response programming model. • Java Technology’s answer to CGI. • Advantages of Java? • Needs a servlet container
  • 20. Servlet Container • Component of a web server that interacts with the Servlets – Manages the Lifecycle of a servlet – Mapping URL to appropriate servlets – Security, concurrency, deployment etc . • Examples – Apache Tomcat (opensource) – Jboss (opensource) – IBM Websphere
  • 21. Tomcat Installation • Follow – http://tomcat.apache.org/tomcat-7.0- doc/appdev/installation.html • Eclipse + Tomcat – http://www.coreservlets.com/Apache-Tomcat- Tutorial/tomcat-7-with-eclipse.html
  • 22. Plain HTML Text Servlet package testPackage; // Always use packages. import java.io.*; import javax.servlet.*; import javax.servlet.annotation.*; import javax.servlet.http.*; @WebServlet("/hello") public class HelloWorld extends HttpServlet { @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println("Hello World"); } }
  • 23. Interpreting the Servlet • @WebServlet("/hello”) – This is the URL relative to the app name – http://knoesis.org:8080/hello • doGet – Code for an HTTP GET request. doPost also common. • HttpServletRequest, HttpServletResponse – Contains anything that comes from the browser – Send data back to the browser • @Override
  • 24. Lets see how to generate a simple HTML <!DOCTYPE html> <html lang="en"> <head> .. </head> <body> ... </body> </html>
  • 25. Servlet that generates HTML @WebServlet("/test1") public class TestServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println ("<!DOCTYPE html>n" +"<html>n" + "<head><title>A Test Servlet</title></head>n" + "<body bgcolor="#fdf5e6">n" + "<h1>Test</h1>n" + "<p>Simple servlet for testing.</p>n" + "</body></html>"); } }
  • 26. Modifying web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4”... > <servlet> <servlet-name>TestServlet</servlet-name> <display-name>Print Text</display-name> <servlet-class>testPackage.TestServlet</servlet-class> <init-param> <param-name> param1 </param-name> <param-value> value1 </param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>TestServlet</servlet-name> <url-pattern>/test2</url-pattern> </servlet-mapping> </web-app> Passing parameters Custom URLs
  • 27. Php • General purpose server-side scripting language originally designed for web development to produce dynamic web pages • Hypertext Preprocessor • Dynamically Typed Language
  • 28. Php – Hello World • Embed PHP script into an HTML file • Upload the file onto a Web server using extension .php (Apache) • Embed using the following delimiters – < ? ... ? > – <?php ... ?> – <script language=”php”> ... </script> – <% ... %>
  • 29. Php – Hello World <html> <body> <?php echo "Hello World"; ?> </body> </html> Delimiters – seperates PHP to non-PHP code <?php ?>
  • 30. Php Applications • Wide range of applications (similar to CGI) – Forms handling, etc. • Wide range of PHP libraries – Network connectivity (e.g. access FTP, IMAP, SMTP, etc – Database connectivity (e.g. MySQL, dBase, Oracle, etc.) – XML/XSLT manipulation – Image manipulation
  • 31. GET – POST • Access form fields through PHP array – $HTTP_POST_VARS for POST method – $HTTP_GET_VARS for GET method – $_POST for POST method (>=PHP4.1.0) – $_GET for GET method (>=PHP4.1.0) $name = $_POST["name"]; $name = $_GET["name"]; • Similar to request.getParameter(“name”) in doPost/doGet in Servlets.
  • 32. Prints even numbers until “max” <html> <head><title>A Test Php</title></head> <body bgcolor="#fdf5e6"> <p> <ul> <?php $maximum = $_GET["max"]; for($i=0; $i<=$maximum ; $i=$i+2){ echo "<li>$i</li>"; } ?> </ul> </p> </body> </html>
  • 33.
  • 34. References • Common – http://coronet.iicm.edu/lectures/mmis/material/s lides_serverside_main.pdf • Servlets – http://courses.coreservlets.com/Course- Materials/pdf/csajsp2/02-Servlet-Basics.pdf • Php – http://www.php.net/ – http://www.w3schools.com/php/
  • 35. Friends Likes and Comments Friends Updates Partial Changes
  • 36. JSON, XML Handling • Change the content type • Construct a Json/XML • Pass it as it is done for plain text or html • More about this in the next class. • Might be a part of the assignment
  • 37. CGI/Perl • 1987 – Before the web • Text manipulation language • CGI – Common Gateway interface – Can run any language – Commonly perl • Advantages – Mature language over a decade of history – Free and most os support perl – Vast network of perl developers • Disadvantage – Scalability – Optimized for unix platform – Different ways of doing the same thing hence not easy to learn

Editor's Notes

  1. Hello, This video we will be talking about server side web programming for the Web Information Systems class of 2015
  2. In the previous videos, you have learnt about HTML , CSS and javascript as a client side programming. For this lecture, you will need some background in one of these languages. Java, Perl, Python and Php. I will touch upon Java and Php in this video and then hopefully if we have sometime talk about Python in the class.
  3. Before we dwell into the programming languages, first, let us learn some basics about web servers. Webservers are programs that delivers web content. As shown in the Figure, the web server receives a request, accesses its static files from the file system and sends the response.
  4. For example, if you type a URL as shown on your browser, the browser sends a request to a server that runs a web server program. The webserver reponds to the request with the appropriate html and css files. Those are displayed on your browser.
  5. Since we now know what web servers do, I will give you some details on the history of it. In 1990 TBL wrote two programs, one of the browser and the other one was the web server. He named it as CERN httpd, since it was developed in CERN. However, lately Apache is the most commonly used web server, i.e 60% of the web servers running are apache. It is opensource and can run on all the Oss. The next popular one is from Microsoft and is called IIS (Internet Information Service). It runs of Windows. There are a few others that are used for high performance.
  6. In this class, we will be working with Apache web server. If you want to run it on your manchines, I would advice on installing either LAMP for linux, Wamp for windows and MAMP for mac. AMP stands for apache, mysql and php. If you just need apache, you can download if from their website.
  7. I just mentioned that web server delivers static web pages. However we see a lot of dynamic information on the web such as weather reports, date and time changes and user information updates. How are these dynamic information updated?
  8. More examples that you are familiar with would be. Facebook news feed updates, likes and comments updates. These happen in near real time. I mean as soon as your friedns on FB updates you get their updates on your page.
  9. User information update. You update your information and then its stored in the server, where you will be able to access or login whenever you get on these websites.
  10. In order to perform these tasks, the data has to be sent from your browser as a request to the web server. The webserver call an appropriate script with the data and perfroms the requested functionality (adds/deletes/modifies or accesses the db) and responds to the request. We need to note here that the request sends some data for the web server to work on.
  11. For example, you put up your email id for registration and then this information is sent to the web server. If the email id is already registered which the web server checks in its database and responds that the email is already registered.
  12. In order to get information to be updated dynamically on the web page. The frontend such as the browser has to send some data for the web server to respond appropriated. For this, we call the http methods on the client side either with Javascript of html forms. In the previous videos, we have learnt about JS, Ajax, JSON and XML. In this video we will learn a little about the HTML forms.
  13. From the front end, one of these http methods can be called that is executed at the server. One is the GET method and the other is the POST method. The difference between get and post method is that, in the GET method data is encoded in the URL where as in the post method data goes with the body. An example is shown where the parameters are sent in the URL. If you use GET, the url with the data will be there in the history. Hence for sensitive information such as passwords it is necessary to use POST method where the data goes in the body. POST is also used to change the state. i.e. adding, deleting the data in the server db where as get is used for idempotent data, just retrieving the data. Idempotent – making multiple requests and getting the same results from the web api. No change in state
  14. As explained, HTML Forms are used to pass the data to the server. It has many features such as text fields, check box and radio button. To learn more about it you can go to the URL mentioned in the presentation.
  15. This is an example, where where we call the method post using the destination url. The input type is a button with value click me.
  16. Now lets get on to the technologies we can use at the server side, to respond to requests from the client side.
  17. Although there are many, I will focus on a few of those in this video. CGI, Java Servlets and Php
  18. CGI is common gateway interface. This is the first server side technology which was started in 1993 but formally defined in 1997. CGI is an interface which calls perl or python scripts at the server side for generating the response. The main drawback is scalability, each request is run as a different process.
  19. Servlets are the Java technology’s answer to CGI. It incorporates all the advantages of Java. However needs a servlet container. If you know Java, it is simply extending a servlet interface in which we define the get and post functions.
  20. The servlet container is a component of web server. It manages the lifecycle of a servlet. It maps the url to appropriate servlets. It also manages many features such as security, concurrency and deployment. Some examples are, Apache Tomcat, Jboss and IBM Websphere.
  21. Tomcat can be installed. Check these websites for it.
  22. As you can see servlets are simple java programs that extends a HttpServlet and implements a doGet and/or a doPost method.
  23. The HTTPSevletRequest and Response objects contains anything that is sent from the browser and has to be sent back to the browser
  24. You can modify the URL and parameters for the servlets using the web.xml file.
  25. Php which is an abbreviation for Hypertext preprocessor is also a popular server side language. It is also a dynamically typed language.
  26. Php embeds html in it. So instead of referring to a html page url in the browser, we will type a .php page. The php code can be embedded using the following delimiters.
  27. This is the hello world program. You can see how the Php code is embedded in the page.
  28. They have a wide range of applications and there are many libraries which can be reused.
  29. Similar to HTTPServletRequest and Response objects, you can access the form fields through array objects in Php
  30. These are the differences between java and Php