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
Basic architecture of the web
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
HTTP protocol Specified by – Based on requests and responses A response can contain any document –MIME ( Multipurpose Internet Mail Extensions ) types – A stateless protocol Normally transported via a TCP/IP connection –Default port is TCP 80
HTTP requests Requests –GET –POST –PUT –HEAD Example request GET HTTP/1.1
HTTP responses HTTP/ OK Server: Microsoft-IIS/4.0 Date: Mon, 29 Apr :50:53 GMT Content-Type: text/html Accept-Ranges: bytes Last-Modified: Wed, 10 Apr :12:34 GMT ETag: "085fb85aae0c11:54fb" Content-Length: University of Portsmouth - Our University...
An error response HTTP/ Object Not Found Server: Microsoft-IIS/4.0 Date: Mon, 29 Apr :58:12 GMT Content-Length: Content-Type: text/html University of Portsmouth - Our University...
Dynamic web pages Four models: –Server-side includes –CGI –Server modules –Auxiliary servers
CGI architecture
CGI specification Specified at
Server module
Auxiliary server
Common web languages Java/JSP ASP (.NET) / C# PHP Perl Ruby on Rails
Architecture of a Java web application
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
Important classes and interfaces 1 All servlets must implement the Servlet interface Class HttpServlet –init/destroy –doGet/doPut –Your servlet will derive from this
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
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
JSP elements Scriptlets Actions Directives Standard tags Custom tags Expression language
Scriptlets Any Java code between Expressions – Declarations – DEPRECATED –Do not use - not XML –Much easier to use JSTL
JSP actions Including other files – –Request time inclusion Accessing beans –
JSP directives Page directive – Include directive – –Translation time inclusion
Java Standard Tag Library (JSTL) Taglib directive – Core – SQL XML Format
Custom tags Implement your own tags Create a Tag Library Definition (tld) file Extend predefined classes Specify your library in directive Use like JSTL tags
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}
Java tools NetBeans –IDE –edit, compile, build, run, debug –lots of wizards –support for Struts –support for Hibernate (through nbxdoclet) Eclipse
Web application system architecture
Model View Controller (MVC)
MVC in Java
Relationship between Struts and Hibernate
Struts information flow
Role of the persistence layer