Download presentation
Presentation is loading. Please wait.
Published bySusan Nichols Modified over 9 years ago
1
Server Side Programming Web Information Systems 2012
2
What has been taught until now ? HTML? CSS? Web Server? Do you know – Java ? – Using APIs and Libraries ?
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 Read Static Files
4
Some 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 normally used as forward and reverse Proxy
5
Apache Download Packages – LAMP -- http://www.lamphowto.com/http://www.lamphowto.com/ – WAMP -- http://www.wampserver.com/en/http://www.wampserver.com/en/ – MAMP -- http://sawmac.com/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
6
Why Dynamic Web Pages ? Examples?
7
Friends Likes and Comments Friends Updates Facebook
8
Forms with Values to input
9
Dynamic Web Pages Web Server Script Request Response DB
10
Email already registered
11
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 http://www.w3.org/TR/html401/interact/forms.ht ml
12
Example
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 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
Technologies CGI Servlets – Need to know Java JSP Php
15
CGI Common Gateway Interface (CGI) – Runs a scripts for every request – New process Drawbacks – Scalability Issues – Fast CGI
16
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
17
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
18
Tomcat Installation Follow – http://tomcat.apache.org/tomcat-7.0- doc/appdev/installation.html 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 http://www.coreservlets.com/Apache-Tomcat- Tutorial/tomcat-7-with-eclipse.html
19
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"); }
20
Interpreting the Servlet @WebServlet("/address”) – This is the URL relative to the app name doGet – Code for an HTTP GET request. doPost also common. HttpServletRequest, HttpServletResponse – Contains anything that comes from the browser – Send Stuff back to the browser @Override
21
Generates HTML.....
22
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 (" \n" +" \n" + " A Test Servlet \n" + " \n" + " Test \n" + " Simple servlet for testing. \n" + " "); }
23
Handling forms
24
Servlet LifeCycle init – Executed once when the servlet is loaded service – Called in a new thread by server for each request. – Dispatches to doGet, doPost, etc. – Do not override this method! doGet, doPost, doBlah – Handles GET, POST, etc. requests. – Override these to provide desired behavior. destroy – Called when server deletes servlet instance. – Not called after each request.
25
Modifying web.xml TestServlet Print Text testPackage.TestServlet param1 value1 TestServlet /test2 Passing parameters Custom URLs
26
Php General purpose server-side scripting language originally designed for web development to produce dynamic web pages Hypertext Preprocessor Dynamically Typed Language
27
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 – –... –
28
Php – Hello World <?php echo "Hello World"; ?> Delimiters – seperates PHP to non-PHP code Delimiters – seperates PHP to non-PHP code
29
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
30
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.
31
Handling Forms A Test Php <?php $maximum = $_GET["max"]; for($i=0; $i<=$maximum ; $i=$i+2){ echo " $i "; } ?>
33
Friends Likes and Comments Friends Updates Partial Changes
34
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
35
References Common – http://coronet.iicm.edu/lectures/mmis/material/s lides_serverside_main.pdf 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 http://courses.coreservlets.com/Course- Materials/pdf/csajsp2/02-Servlet-Basics.pdf Php – http://www.php.net/ http://www.php.net/ – http://www.w3schools.com/php/ http://www.w3schools.com/php/
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.