1 / 51

Web Applications - Basics

Web Applications - Basics. Introduction to Web. Web features Clent/Server HyperText Transfer Protocol HyperText Markup Language URL addresses Web server - a computer program that is responsible for accepting HTTP requests from clients and serving them HTTP responses

Download Presentation

Web Applications - Basics

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 Applications - Basics

  2. Introduction to Web • Web features • Clent/Server • HyperText Transfer Protocol • HyperText Markup Language • URL addresses • Web server - a computer program that is responsible for accepting HTTP requests from clients and serving them HTTP responses • Web application- a dynamic extension of a web or application server

  3. Web (HTTP) servers • A Web server handles the HTTP protocol • To process a HTTP request, a Web server may • respond with a static HTML page or image • send a redirect • delegate the dynamic response generation to some other program such as • CGI scripts • JSPs (JavaServer Pages), servlets • server-side JavaScripts • or some other server-side technology

  4. Web server diagram http://www.resultantsys.com/appServer.htm

  5. Web server features In practice many web servers implement the following features: • Authentication • Handling of static and dynamic content • HTTPS support (by SSL or TLS) • Content compression (i.e. by gzip encoding) • Virtual hosting • Large file support • Bandwidth throttling

  6. Web server statistics Web server software vendors statistics http://news.netcraft.com/archives/web_server_survey.html Totals for Active Sites Across All Domains:

  7. Web server statistics Web server software vendors statistics http://news.netcraft.com/archives/web_server_survey.html

  8. Application servers • Application server is responsible for handling the business logic of the system • Separation of business logic from the presentation logic and the database logic: 3-tier architecture http://www.cavehill.uwi.edu/fpas/cmp/online/cs14k/client_server_model/webserver.htm

  9. Application server diagram Application servers extend web servers to support dynamic content http://www.resultantsys.com/appServer.htm

  10. Application server features • The application server manages its own resources and may provide features such as: • Security • Transaction management • Database connection pooling • Clustering support • Messaging • Most application servers also contain a Web server

  11. Web Applications & Components • Web application is a dynamic extension of a web or application server • Two types of web applications: • Presentation-oriented (HTML, XML pages) • Service-oriented (Web services) • Web components provide the dynamic extension capabilities for a web server: • Java servlets • JSP pages • Web service endpoints

  12. Web Application Interaction • [client] sends an HTTP request to the web server • [web server]HTTP request HTTPServletRequest • This object is delivered to a web component, which can interact with JavaBeans or a DB to generate dynamic content • [web component] generates an HTTPServletResponse or pass the request to another web component • [web server]HTTPServletResponse HTTP response • [web server] returns HTTP response to the client

  13. Web Application Interaction

  14. Java Enterprise Edition • Java EE is a comprehensive platform for multi-user, enterprise-wide applications • It is based on Java SE and adds APIs for Internet-based server-side computing http://download.oracle.com/javaee/6/tutorial/doc/

  15. Java EE architecture Java EE defines an architecture for implementing services through the use of a Java EE server as multi-tier applications that deliver the scalability, accessibility, and manageability needed by enterprise-level applications • The business and presentation logic has to be implemented by the developer • The standard system services are provided by the Java EE platform

  16. Java EE versions • J2EE 1.2 (December 12, 1999) • Java EE 5 (May 11, 2006) • Java EE 6 (Dec 10, 2009) • Java EE 7 Roadmap https://blogs.oracle.com/theaquarium/entry/java_ee_7_roadmap • Java EE 7 – spring 2013 • Java EE 8 – spring 2015

  17. Java EE 6 technologies • Web Application Technologies • Java Servlet 3.0 • JavaServer Pages 2.2 • JavaServer Faces 2.0 • Web Services Technologies • JAX-RS 1.1, JAX-WS 2.2, JAXB 2.2, StAX … • Enterprise Application Technologies • EJB 3.1, JMS, JPA, JTA, JavaMail … http://www.oracle.com/technetwork/java/javaee/tech/index.html

  18. Java EE components • Java EE applications are made up of components • A Java EE component is a self-contained functional software unit that is assembled into a Java EE application with its related classes and files and that communicates with other components

  19. Java EE components • Components are compiled in the same way as any program in the Java language • Components are assembled into a Java EE application, are verified to be in compliance with the Java EE specification, and are deployed to production, where they are run and managed by a Java EE server

  20. Java Web Application Technologies Java Servlet technology is the foundation of all the web application technologies

  21. Servlets and JSPs • Servlets- Java classes that dynamically process requests and construct responses • JSP pages - text-based documents that execute as servlets, but allow a more natural approach to creating static content • Appropriate usage • Servlets - service-oriented applications, control functions • JSP - generating text-based markup (HTML, SVG, WML, XML)

  22. Web Containers • Web components are supported by the services of a runtime platform called a web container • In Java EE, a web container "implements the web component contract of the Java EE architecture“ • Web container services: • request dispatching • security • concurrency • life-cycle management • naming, transactions, email APIs

  23. Web Container Examples • Non-commercial • Apache Tomcat • Jetty • Commertial • Sun Java System Application Server • BEA WebLogic Server • Oracle Application Server • WebSphere • Open source • JBoss

  24. Deployment • Web components have to be installed or deployed to the web container • Aspects of web application behaviour can be configured during application deployment • The configuration information is maintained in a XML file called a web application deployment descriptor

  25. Web Application Development • A web application consists of: • Web components • Static resource files (such as images, css) • Helper classes and libraries • The process for creating and running a web application is different from that of traditional stand-alone Java classes

  26. Development Cycle • Develop the web component code • Develop the web application deployment descriptor • Compile the web application components and helper classes referenced bythe components • Optionally package the application into a deployable unit • Deploy the application into a web container • Access a URL that references the web application

  27. Web Modules • According to Java EE architecture and Java Servlet Specification: • Web components and static web content files such asimages are called web resources • A web module is the smallest deployable andusable unit of web resources • Web module corresponds to a webapplication • A web module has a specific structure

  28. Web Module Structure • The top-level directory of a web moduleis the document root of the application • The document root contains: • JSP pages • client-side classes • client-side archives • static web resources

  29. Web Module Structure • The document root contains a subdirectory /WEB-INF/ • web.xml: web application deployment descriptor • lib: JAR archives of libraries called by server-side classes

  30. Web Module Structure • classes: server-side classes: • servlets • utility classes • JavaBeans components • tags: tag files, which are • implementations of • tag libraries

  31. Configuring Web Applications • Web applications are configured via deployment descriptor /WEB-INF/web.xml file • Configuration options: • Map URLs to web components • Set initialization parameters • Map errors to error screens • Declare welcome files • Declare resource references

  32. Mapping URLs to Web Components • When a request is received by the web container it must determine which web component should handle the request • Need to add a servlet definition and a servlet mapping for each servlet to web.xml file <servlet> <servlet-name>ServletName</servlet-name> <servlet-class>ServletClass</servlet-class> </servlet> <servlet-mapping> <servlet-name>ServletName</servlet-name> <url-pattern>/path</url-pattern> </servlet-mapping>

  33. Initialization Parameters • It's possible to pass initialization parameters to the context or to a web component • Context parameters: <context-param> <param-name>name</param-name> <param-value>value</param-value> </context-param> • Servlet parameters (within servlet definition): <init-param> <param-name>name</param-name> <param-value>value</param-value> </init-param>

  34. Handling Errors • Web container generates default error page • You can specify custom default page to be displayed instead • Steps to handle errors • Create appropriate error HTML pages for error conditions • Modify the web.xml accordingly

  35. Example: Setting Error Pages <error-page> <exception-type> exception.BookNotFoundException </exception-type> <location>/errorpage1.html</location> </error-page> <error-page> <exception-type> exception.BooksNotFoundException </exception-type> <location>/errorpage2.html</location> </error-page> <error-page> <exception-type> exception.OrderException </exception-type> <location>/errorpage3.html</location> </error-page>

  36. Example: web.xml <?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name>Your team project name</display-name> <description>Team N servlets</description> <context-param> <param-name>name_of_context_initialization_parameter</param-name> <param-value>value_of_context_initializtion_parameter</param-value> </context-param> <servlet> <servlet-name>MyServlet</servlet-name> <servlet-class>com.web.demo.MyServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>MyServlet</servlet-name> <url-pattern>/servlet</url-pattern> </servlet-mapping> </web-app>

  37. WAR Files • A web module can be deployed as an unpacked file structure or can be packaged in a JAR file known as a Web Archive File • WAR file can be created by: • executing jar command • using Ant target • using IDE (Eclipse for instance) • using Maven

  38. Setting a Context Root • A context rootidentifies a web application in a Java EE server • The server is responsible for mapping URL’s that start with a specific prefix to the location of a web application • Usually this is done with a web server configuration file

  39. Using Maven & Jetty • A convenient way to develop, build, deploy and run Web application is by using: • Maven build tool http://maven.apache.org/ • Jetty web server http://www.mortbay.org/

  40. Creating Directory Structure • Maven supports the notion of creating a complete project template with a simple command • To create Web project template need to use maven-archetype-webapp archetype type in a single line: mvn archetype:create -DgroupId=com.maven2example -DartifactId=maven2example_webapp -DarchetypeArtifactId=maven-archetype-webapp

  41. Maven Web Directory Structure <root>/src/main/webapp/ - directory structure for a WAR

  42. Packaging • Executing the command mvn package creates a WAR file

  43. Running with Jetty • It’s easy to run application by using Jetty plugin for Maven • Jetty is an open-source, standards-based, full-featured web server implemented entirely in Java • First created in 1995 • Stable release: 8.1.7 / 2012-07-16

  44. Jetty Maven Plugin • Useful for rapid development and testing • You can add it to any webapp project that is structured according to the usual Maven defaults • The plugin can then periodically scan your project for changes and automatically redeploy the webapp if any are found http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin

  45. Running with Jetty • Add the Jetty plugin to the pom.xml <build> <finalName>maven2example_webapp</finalName> <plugins> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>8.1.7.v20120910</version> </plugin> </plugins> </build>

  46. Running with Jetty • Execute mvn jetty:run command >mvn jetty:run [INFO] Scanning for projects... [INFO] ------------------------------------------------------- [INFO] Building maven2example_webapp Maven Webapp 1.0-SNAPSHOT [INFO] ------------------------------------------------------- [INFO] >>> jetty-maven-plugin:8.1.7.v20120910:run (default-cli) @ maven2example_webapp >>> ... ... 2012-11-01 05:14:02.035:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:8080 [INFO] Started Jetty Server Stop by Ctrl+C

  47. Opening the Application Open your web browser to http://localhost:8080/

  48. Configuration <build> <finalName>maven2example_webapp</finalName> <plugins> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>8.1.7.v20120910</version> <configuration> <scanIntervalSeconds>10</scanIntervalSeconds> <webApp> <contextPath>/my-super-app</contextPath> </webApp> </configuration> </plugin> </plugins> </build> Now valid URL is: http://localhost:8080/my-super-app

  49. Opening the Application Open your web browser to http://localhost:8080/

  50. Resources • Article “Introducing the Java EE 6 Platform” http://www.oracle.com/technetwork/articles/javaee/javaee6overview-141808.html • The Java EE 6 Tutorial http://download.oracle.com/javaee/6/tutorial/doc/ • Article “App server, Web server: What's the difference?” http://www.javaworld.com/javaqa/2002-08/01-qa-0823-appvswebserver.html

More Related