1 / 33

Web programming for project students

Web programming for project students. Dr Jim Briggs. What is the web?. Distributed system Client-server system Characteristics of clients and servers Servers always on / Clients choose when on Clients do not need high performance if the work is done on the server Protocol based.

Download Presentation

Web programming for project students

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Web programmingfor project students Dr Jim Briggs

  2. What is the web? • Distributed system • Client-server system • Characteristics of clients and servers • Servers always on / Clients choose when on • Clients do not need high performance if the work is done on the server • Protocol based

  3. Basic architecture of the web

  4. Browsers Microsoft Internet Explorer Netscape Navigator Mozilla (Firefox) Opera Safari Konqueror Lynx Servers Apache Internet Information Server (Microsoft) Sun Netscape Omni Roxen NCSA Common web tools

  5. HTTP protocol • Specified by • http://www.w3.org/Protocols/rfc2616/rfc2616.html • Based on requests and responses • A response can contain any document • MIME (Multipurpose Internet Mail Extensions) types • http://www.iana.org/assignments/media-types/ • A stateless protocol • Normally transported via a TCP/IP connection • Default port is TCP 80

  6. HTTP requests • Requests • GET • POST • PUT • HEAD • Example request GET http://www.port.ac.uk/index.htm HTTP/1.1

  7. HTTP responses HTTP/1.1 200 OK Server: Microsoft-IIS/4.0 Date: Mon, 29 Apr 2002 08:50:53 GMT Content-Type: text/html Accept-Ranges: bytes Last-Modified: Wed, 10 Apr 2002 16:12:34 GMT ETag: "085fb85aae0c11:54fb" Content-Length: 13845 <HTML> <HEAD> <TITLE>University of Portsmouth - Our University</TITLE> ...

  8. An error response HTTP/1.1 404 Object Not Found Server: Microsoft-IIS/4.0 Date: Mon, 29 Apr 2002 08:58:12 GMT Content-Length: 11891 Content-Type: text/html <HTML> <HEAD> <TITLE>University of Portsmouth - Our University</TITLE> ...

  9. Dynamic web pages • Four models: • Server-side includes • CGI • Server modules • Auxiliary servers

  10. CGI architecture

  11. CGI specification • Specified at http://hoohoo.ncsa.uiuc.edu/cgi/

  12. Server module

  13. Auxiliary server

  14. Common web languages • Java/JSP • ASP (.NET) / C# • PHP • Perl • Ruby on Rails

  15. Architecture of aJava web application

  16. Introduction to Java web apps • Servlets and JSPs • Servlet container • Tomcat • A container may run several (independent) web applications (webapps) • Each must have a WEB-INF directory: • web.xml configuration file • classes directory • lib directory

  17. Important classes and interfaces 1 • All servlets must implement the Servlet interface • Class HttpServlet • init/destroy • doGet/doPut • Your servlet will derive from this

  18. Important classes and interfaces 2 • 2 parameters to a request handling method • Class HttpServletRequest • String param = request.getParameter(name); • Class HttpServletResponse • PrintWriter out = response.getWriter(); • Class HttpSession • Holds data common to related requests

  19. JavaServer Pages (JSP) • Distinction: • servlets: HTML embedded in program • JSP: program embedded in HTML • Useful where majority of effort is page design • Translated automatically into a servlet • Retranslated if changed (no need to restart server) • Can be placed anywhere in a web application • but not visible to client if in the WEB-INF directory

  20. JSP elements • Scriptlets • Actions • Directives • Standard tags • Custom tags • Expression language

  21. Scriptlets • Any Java code between <% … %> • Expressions • <%= name %> • Declarations • <%! String name %> • DEPRECATED • Do not use - not XML • Much easier to use JSTL

  22. JSP actions • Including other files • <jsp:include page="path"/> • Request time inclusion • Accessing beans • <jsp:usebean id="beanName" class="package.class" scope="session"/> • <jsp:getproperty name="beanName" property="propertyName"/> • <jsp:setproperty name="beanName" property="propertyName" value="newValue"/>

  23. JSP directives • Page directive • <%@page import="package.class"%> • <%@page contentType="text/html"%> • <%@page errorPage="URL"%> • Include directive • <%@include file="filename"%> • Translation time inclusion

  24. Java Standard Tag Library (JSTL) • Taglib directive • <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> • Core • <c:out value="${anExpression}"/> • SQL • XML • Format

  25. Custom tags • Implement your own tags • Create a Tag Library Definition (tld) file • Extend predefined classes • Specify your library in a @taglib directive • Use like JSTL tags

  26. Expression language • Refer to Java Beans and other common classes • ${expression} can appear as tag attributes or (since JSP 2.0) in the page itself • Several implicit objects: • header • ${header["user-agent"]} • param • ${param['name']} • ${param.name}

  27. Java tools • NetBeans • IDE • edit, compile, build, run, debug • lots of wizards • support for Struts • support for Hibernate (through nbxdoclet) • Eclipse

  28. Web applicationsystem architecture

  29. Model View Controller (MVC)

  30. MVC in Java

  31. Relationship betweenStruts and Hibernate

  32. Struts information flow

  33. Role of the persistence layer

More Related