Web programming for project students - PowerPoint PPT Presentation

1 / 33
About This Presentation
Title:

Web programming for project students

Description:

Clients do not need high performance if the work is done on ... DEPRECATED. Do not use - not XML. Much easier to use JSTL. JSP actions. Including other files ... – PowerPoint PPT presentation

Number of Views:49
Avg rating:3.0/5.0
Slides: 34
Provided by: JimBr87
Category:

less

Transcript and Presenter's Notes

Title: Web programming for project students


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
Common web tools
  • Browsers
  • Microsoft Internet Explorer
  • Netscape Navigator
  • Mozilla (Firefox)
  • Opera
  • Safari
  • Konqueror
  • Lynx
  • Servers
  • Apache
  • Internet Information Server (Microsoft)
  • Sun
  • Netscape
  • Omni
  • Roxen
  • NCSA

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 085053 GMT
  • Content-Type text/html
  • Accept-Ranges bytes
  • Last-Modified Wed, 10 Apr 2002 161234 GMT
  • ETag "085fb85aae0c1154fb"
  • Content-Length 13845
  • ltHTMLgt
  • ltHEADgt
  • ltTITLEgtUniversity of Portsmouth - Our
    Universitylt/TITLEgt
  • ...

8
An error response
  • HTTP/1.1 404 Object Not Found
  • Server Microsoft-IIS/4.0
  • Date Mon, 29 Apr 2002 085812 GMT
  • Content-Length 11891
  • Content-Type text/html
  • ltHTMLgt
  • ltHEADgt
  • ltTITLEgtUniversity of Portsmouth - Our
    Universitylt/TITLEgt
  • ...

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 lt gt
  • Expressions
  • lt name gt
  • Declarations
  • lt! String name gt
  • DEPRECATED
  • Do not use - not XML
  • Much easier to use JSTL

22
JSP actions
  • Including other files
  • ltjspinclude page"path"/gt
  • Request time inclusion
  • Accessing beans
  • ltjspusebean id"beanName" class"package.class"
    scope"session"/gt
  • ltjspgetproperty name"beanName"
    property"propertyName"/gt
  • ltjspsetproperty name"beanName"
    property"propertyName" value"newValue"/gt

23
JSP directives
  • Page directive
  • lt_at_page import"package.class"gt
  • lt_at_page contentType"text/html"gt
  • lt_at_page errorPage"URL"gt
  • Include directive
  • lt_at_include file"filename"gt
  • Translation time inclusion

24
Java Standard Tag Library (JSTL)
  • Taglib directive
  • lt_at_ taglib prefix"c" uri"http//java.sun.com/jst
    l/core" gt
  • Core
  • ltcout value"anExpression"/gt
  • 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 _at_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
Write a Comment
User Comments (0)
About PowerShow.com