Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Advanced Internet Programming Week 1 Instructor: Dan Slack, P.Eng Applied Computer Science University of Winnipeg Welcome! What is this class about? Preliminaries Servlets Overview Server Setup and configuration Exercise Advanced Internet Programming What is this course about? ACS-2909 taught us front end development using Javascript How can users see our creations? Servers! Many different technologies .Net, PHP, Rails, etc. We will be talking about JavaEE and NodeJS Java and Javascript based respectively Preliminaries ACS User Accounts Username: <first initial><last name> Password: <student number>ACS! Please contact Daniel Sheppard to resolve any problems [email protected] Office: 3D19 Course Website Check the course site regularly http://courses.acs.uwinnipeg.ca/3909-050 Updates will be posted frequently Group Page All questions will be answered via the group page https://groups.google.com/forum/#!forum/uw_2017winter_3909 Textbooks You are responsible for all information given in class, slides, extra notes First Half of Course Core Servlets and JavaServer Pages; 2nd Edition; Marty Hall, Larry Brown; Prentice Hall 2004, ISBN: 0-13-009229-0 http://pdf.coreservlets.com/ Second Half of Course Express in Action; 1st Edition; Evan M. Hahn; Manning Publications 2016, ISBN 1-61729242-7 https://www.manning.com/books/express-in-action Syllabus The course syllabus can be downloaded from the website Classroom Procedure Be on time, and stay until the end Ask questions anytime (the more the better) Turn cell phones off (or on vibrate) Lecture Format Lectures are once a week Expect two “normal” classes crammed into one Breaks will be around 1:15 into class, for 15 minutes Lectures will consist of Slides Problems and examples solved in class Current developments Slides will be posted day of class Lecture 1 Servlets, Java, Netbeans Netbeans Development Environment We will be using Netbeans for the first half of the course Should already be installed on class machines Free Available at https://netbeans.org/downloads/index.html Select “Java EE” version When installing, select Tomcat as server Netbeans Create a new Project Java Web Target Server Tomcat Java EE 5 Context Path Where you will navigate to Target Server Deploying an Application Servlets Serving Files Webserver is there to respond to requests for web pages From any source, but typically, a browser Servers you may have seen File storage Like how you download lecture slides Static HTML Think back to Web Workers Needed a server for permissions Serving Files Servers in this course Determine appropriate action to take Creates appropriate document to respond to Returns document to client Dynamic Behaviour Content returned can be completely dynamic We write “applications” that look at request, and create page to be returned Server runs “application” and returns output to client Serving Files Dynamic Pages Server constructs page based on server-side processing Web Applications Basically same, except that design is similar to desktop applications Semantics! Primarily the design philosophy The course website are Dynamic Pages, not a web app Why Dynamically? For the client, static might be acceptable Data would be passed back to the client without invoking any servlets Really fast response! Many problems with this from a client AND, a developer perspective Why Dynamically? From a Developer Perspective How do we update the content? From a Clients perspective No possibility of interactivity No persistence Why Dynamically Specific issues: When a page is generated, it is based on data sent from user Search engine results or a confirmation for an online order The generated page is derived from data that changes frequently Weather, stocks, news or analytics The data itself is stored and retrieved from a database (or other data sources) E-commerce site Servlets – What are they? Servlets are Java based programs that are executed on a Web or Application Server Acts as a middle layer between requests from a client Could be a browser or other HTTP Client And databases or other applications on the server itself Servlets – What do they do? Servlets are primarily used for: Reading data from a client Forms (explicit) Cookies, headers, other data sent with browser request (implicit) Generates Results By communicating with the database, doing computations Returns data back to the client HTML, Images, Excel, etc. (explicit) Status codes, document type, setting cookies (implicit) Servlets – When to use them? When the web page is based on data sent by the client The web page is derived from data that changes frequently The web page uses information from databases or other server-side sources Primarily used as to handle HTTP Requests Could also provide capability as FTP or even mail server Generally not used in this way Advantages Efficient For each HTTP Request to a Servlet: New Thread (not process) is started Only one copy of servlet class is loaded Remains in memory useful for caching, DB connections, etc Convenience If you know Java, you don’t need another programming language Powerful Can talk to web server Multiple Serviets can share data Maintain Information from request to request (session tracking) Advantages Portable Written in Java Compatible on any JVM Supported (directly or by plugin) by most web servers Inexpensive Many free/open source web services Secure Run within JVM, not in an OS shell Mainstream Supported by Apache, Oracle, IBM, SAP, IDEA, Microsoft, W3C, etc. Example Example JavaServer Pages (JSP) Servlets could be described as Java programs with HTML embedded inside of them JSPs could be described as HTML pages with Java code embedded These are oversimplified descriptions In fact, JSPs are actually another way of writing servlets Get translated into servlets, Get compiled Run as a servlet Sample JSP Sample JSP JSP vs. Servlets If JSPs and Servlets are essentially the same, does it mater which to use? Yes! Servlets are best for tasks oriented toward processing JSP is best for tasks oriented toward presentation HTTP Overview Hypertext Transfer Protocol Protocol used to deliver resources on the World Wide Web Uses client-server model 1. client opens a connection to a server 2. client sends a request message 3. server returns a response message 4. server closes the connection HTTP Overview Request/response message format Both messages consist of: 1. An initial line 2. One or more header lines 3. A blank line (CRLF by itself) 4. An optional message body a file, or query data, or query output Use CRLF to end lines (ASCII 13 and 10) 1. Initial Line (Request) The initial line is different for the request and response Initial Request Line consists of three parts (separated by spaces): A method name Local path of the requested resource Part of the URL after the host name (called the request URI) Version of HTTP being used e.g. Always take the form HTTP/x.x GET /path_to_file/index.html HTTP/1.0 1. Initial Line (Request) HTTP Request Methods Get is the most common HTTP method Besides GET, the two most commonly used methods are HEAD and POST 1. Initial Line (Request) HEAD Asks for the response identical to the one that would correspond to a GET request, but without the response body. GET Requests a representation of the specified resource. POST Submits data to be processed (e.g. from an HTML form) to the identified resource. The data is included in the body of the request. PUT Uploads a representation of the specified resource. 1. Initial Line (Request) DELETE Deletes the specified resource. TRACE Echoes back the received request, so that a client can see what intermediate servers are adding or changing in the request. OPTIONS Returns the HTTP methods that the server supports. CONNECT Converts the request connection to a transparent TCP/IP tunnel, usually to facilitate SSL-encrypted communication (HTTPS). 1. Initial Line (Response) Initial Response Line (Status Line) also has three parts (separated by spaces) HTTP version Same format as request A response status code An English phrase describing the status code e.g. HTTP/1.0 200 OK 1. Initial Line (Response) Status code categories 1xx indicates an informational message only 2xx indicates success of some kind 3xx redirects the client to another URL 4xx indicates an error on the client's part 5xx indicates an error on the server's part e.g. 200 OK, 404 Not Found, 500 Server Error 2. Header Lines Head lines provide information about the request or response Or about the object sent in the message body Header Line format Header_name: value Should end in CRLF Not case-sensitive (value may be) Any number of spaces between ‘:’ and value Lines beginning with space or tab are part of previous header Following headers are equivalent: Header: value1, value2 HEADER: value1, value2 3. Blank Line Slide intentionally left CRLF 4. Message Body HTTP messages may have data after header lines e.g. Response: body contains requested resource for client Most common use of message body Request: User entered data or uploaded files References http://en.wikipedia.org/wiki/HTTP http://www.jmarshall.com/easy/http/ "Core Servelet and JavaServer Pages" 2nd ed., http://pdf.coreservlets.com/ RFC 959, http://www.faqs.org/rfcs/rfc959.html Request For Comments, http://www.rfc-editor.org/ http://www.ubuntu.com/ http://fabrice.bellard.free.fr/qemu/ http://www.chiark.greenend.org.uk/~sgtatham/putty/