1 / 125

Developing Web Applications

Developing Web Applications. Using Ada, JGNAT, JavaServer Pages, and JDBC to Build Web Applications Terry Westley SIGAda 2001. What Will You Learn?. Overview of dynamic web technologies Create HTML pages that use JavaServer Pages (JSP) technology to access and display dynamic web content

hester
Download Presentation

Developing Web Applications

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. Developing Web Applications Using Ada, JGNAT, JavaServer Pages,and JDBC to Build Web Applications Terry Westley SIGAda 2001

  2. What Will You Learn? • Overview of dynamic web technologies • Create HTML pages that use JavaServer Pages (JSP) technology to access and display dynamic web content • Write Java Beans and Java servlets in Ada • Use JDBC in Ada to create, maintain, and query a relational database

  3. Tutorial Prerequisites • We assume you are familiar with: • Creating static HTML pages • Programming in Ada • But, not: • Programming in Java • SQL • JavaServer Pages

  4. References • DuBois, Paul, MySQL, New Riders, Indianapolis, IN, 2000. • Fields, Duane K., Kolb, Mark A., Web Development with JavaServer Pages, Manning Publications Co., Greenwich, CT, 2000. • Goodman, Danny, Dynamic HTML, The Definitive Reference, O'Reilly and Associates, Sebastopol, CA, 1998. • Horstmann, Cay S., Cornell, Gary, Core Java 1.1, Volume I -- Fundamentals, Prentice Hall, Upper Saddle River, NJ, 1997. • Lemay, Laura, Perkins, Charles L., Morrison, Michael, Teach Yourself Java in 21 Days, Professional Reference Edition, Sams Publishing, Indianapolis, IN, 1996.

  5. Table of Contents • Dynamic Web Technologies • Required Components • Introduction to JSP • Introduction to Java Beans • Introduction to JDBC • Building a Web Application

  6. What is a Dynamic Web? What do I mean by "dynamic?" • User interaction affects the HTML page • Data from a server affects the HTML page

  7. Dynamic Web Technologies • Static HTML pages • Common Gateway Interface (CGI) • JavaScript • Java applets • Dynamic HTML (DHTML) • Java servlets • Template systems

  8. Static HTML • Browser requests an HTML document • Server finds the file and sends it to browser via HTTP • Server sends image files separately • Static HTML example

  9. Browser Server Static HTML Page Request Page Image

  10. Common Gateway Interface (CGI) • Server-side processing • Usually used in conjunction with HTML forms • HTTP request is passed to a separate program which processes it and generates a response • David Wheeler's AdaCGI: • http://www.dwheeler.com/ • CGI example

  11. Browser Server CGI Program Common Gateway Interface (CGI) Page Request Spawn HTTP Request Page Page

  12. JavaScript • Client-side processing (in browser) • First introduced by Netscape • Object-based language with access to Document Object Model (DOM) • Small application whose source code is embedded in an HTML page and interpreted by the browser • JavaScript example

  13. Browser Server JavaScript Page Request Page Image

  14. Java Applets • Client-side processing • Small applications that server sends to browser as a separate file • Browser invokes the Java Virtual Machine to execute the applet • Applet may or may not have a user interface • Applet is discarded when user switches to another page • Java Applet example

  15. Browser Server Java VirtualMachine Java Applets Page Request Page Applet Applet User Interface

  16. Dynamic HTML (DHTML) • Client-side processing • DHTML is a combination of World Wide Web Consortium (W3C) standards for: • HTML 4.0 • JavaScript • Document Object Model (DOM) • Cascading Style Sheets (CSS)

  17. Browser Server Dynamic HTML (DHTML) Page Request Page Image

  18. Java Servlets • Server-side processing • Small Java applications that server executes • Similar to CGI except does not require spawning a new process • Servlet processes the HTTP request and generates the response • Java servlet example

  19. Browser Server Java ServletContainer Java Servlets Page Request HTTP Request SpawnServletThread Page Page

  20. Template Systems • Server-side processing • Embedded in HTML file: • Special tags request dynamic content • Scripts generate more HTML • Server processes the HTML file, filling in the dynamic content and executing the scripts, then passing the page to the browser

  21. Browser Server TemplateProcessor Template Systems Page Request HTTP Request Page Page

  22. Template Systems • ColdFusion • Microsoft Active Server Pages (ASP) • Server Side JavaScript • PHP • WebMacro • Apache Velocity • JavaServer Pages

  23. Why JavaServer Pages? • Platform-independent technology • Java-based technology • Full object-oriented programming model • Access to Java platform, including all Java APIs • Improved performance over CGI and scripting languages

  24. Why JavaServer Pages (2) • A programming model which provides for • Separation of presentation and implementation • Reusable component model: Java Beans • Tag extension mechanism • Last, but not least: • Use Ada to code Java Beans and Java servlets • Complete set of free tools

  25. Table of Contents • Dynamic Web Technologies • Required Components • Introduction to JSP • Introduction to Java Beans • Introduction to JDBC • Building a Web Application

  26. Required Components • Java Software Development Kit (SDK) • Ada to JVM compiler • JGNAT • Aonix ObjectAda • Relational database – MySQL • JDBC driver • JSP-enabled web server – Jakarta Tomcat

  27. Java SDK • Get “Java 2 Standard Edition” • Windows version: j2sdk1_3_0-win.exe • http://java.sun.com • Install on • server • development computer

  28. Test Java SDK Installation • Create file HelloJavaWorld.java: class HelloJavaWorld { public static void main (String args[]) { System.out.println ("Hello Java World!"); } } • Compile it: javac HelloJavaWorld • Execute it: java HelloJavaWorld • Should display: Hello Java World!

  29. Ada to JVM Compiler • Ada compiler targeted to the Java Virtual Machine (JVM) • JGNAT by Ada Core Technologies • Aonix ObjectAda

  30. JGNAT • Get JGNAT • Windows version: jgnat-1.1p-nt.exe • ftp://ftp.cs.nyu.edu/pub/gnat/jgnat/ • ftp://ftp.freesoftware.com/pub/ada/compiler/gnat/distrib/jgnat/ • Install on development computer only

  31. JGNAT Environment Variables • Remove: • ADA_INCLUDE_PATH • ADA_OBJECTS_PATH • Add to PATH: • SET PATH=C:\JGNAT-1.1P\BIN;%PATH% • Add CLASSPATH: • SET CLASSPATH=.;C:\JGNAT-1.1P\LIB\JGNAT.JAR;%CLASSPATH% Dot is important; don’t leave it out!

  32. Test JGNAT Installation • Create file hello.adb: with Ada.Text_IO; procedure HelloJGNAT is begin – HelloJGNAT Ada.Text_IO.Put_Line (“Hello, JGNAT World!"); end HelloJGNAT; • Compile it: jgnatmake hellojgnat • Execute it: java hellojgnat • Should display: Hello, JGNAT World!

  33. Get MySQL • MySQL is an open-source (GPL) relational database (http://www.mysql.com) • Also available with non-GPL commercial license • Support available from TcX DataKonsult AB • See excellent user reference manual in Docs directory for installation, testing instructions and a tutorial • Install on server and development computers

  34. MySQL Security • Remove anonymous user • mysql> delete from mysql.user where user=“”; • Give root a password • shell> mysqladmin –u root password <password> • Require passwords of all users and grant only needed privileges • Generally, only select, update, delete, and insert • mysql> grant select, update, delete, insert on <database> to <user> identified by “<password>”;

  35. JDBC Driver • Java driver that supports Java API for using ODBC to connect to relational databases • Check http://www.mysql.com/ for available JDBC drivers for MySQL • For this tutorial, we will use Mark Matthews' driver found at http://www.worldserver.com/mm.mysql/ • Install on server and development computers

  36. Get Jakarta Tomcat • An open-source (Apache Software Foundation) implementation of Sun's reference edition JSP-enabled web server • http://jakarta.apache.org/ • Can be run stand-alone or from within Apache • Install on server and development computers

  37. Tomcat Environment Variables • Set environment variables • SET TOMCAT_HOME=C:\PROGRA~1\JAKARTA-TOMCAT • SET JAVA_HOME=C:\JDK1.3

  38. Windows 95/98/ME • Use bin\startup.bat to start Tomcat • Use bin\shutdown.bat to stop Tomcat • May have to increase "Initial environment" memory size of startup.bat and shutdown.bat scripts to 2816

  39. Windows 2000/XP • Can run Tomcat as a service • See instructions in Tomcat documentation for installation and configuration • wrapper.tomcat_home • wrapper.java_home • wrapper.class_path • Example: wrapper.properties

  40. Test Tomcat • Start web server using startup.bat script from Tomcat bin directory • Start web browser • Go to http://localhost:8080/ to see local Tomcat home page • Try out some of the JSP and servlet examples • To shutdown web server, use shutdown.bat script from Tomcat bin directory

  41. Table of Contents • Dynamic Web Technologies • Required Components • Introduction to JSP • Introduction to Java Beans • Introduction to JDBC • Building a Web Application

  42. My First JSP <HTML><BODY>Hello, World!</BODY></HTML> • JSP example

  43. Interactive JSP <HTML><BODY><% String visitor = request.getParameter("name"); if (visitor == null) visitor = "World";%>Hello, <%= visitor %></BODY></HTML> Script Tag See Interactive JSP example

  44. Browser Server JSPContainer JSP Processing Page Request HTTP Request CompilePage SpawnServletThread Page Page

  45. Factorial • Another JSP example • Compute and display factorials • All Java code in JSP document

  46. The Bean Edition <html><body><jsp:useBean id="hello" class="hellobean$typ"/><jsp:setProperty name="hello" property="name" param="name"/>Hello,<jsp:getProperty name="hello" property="name"/>!</body></html> See Bean example

  47. Browser Server JSPContainer JSP Bean Processing Page Request HTTP Request Compile Page Spawn Servlet Thread Create Bean setProperty getProperty Page Page

  48. JSP Script Tags • Declarations <%! String visitor %> • Scriptlets <% visitor = request.getParameter("name"); if (visitor == null) visitor = "World"; %> • Expressions <%= visitor %>

  49. JSP XML Tags • Declarations <jsp:declaration> String visitor </jsp:declaration> • Scriptlets <jsp:scriptlet> visitor = request.getParameter("name"); if (visitor == null) visitor = "World";</jsp:scriplet> • Expressions <jsp:expression> visitor </jsp:expression>

  50. JSP Bean Tags • Create a bean <jsp:useBean id="hello" class="hellobean$typ"/> • Set bean property <jsp:setProperty name="hello" property="name" param="name"/> • Get bean property <jsp:getProperty name="hello" property="name"/>

More Related