Unformatted text preview:

Lab 4 Due Monday, December 10, 2001Submission DetailsFiles that you writeFiles that are provided on the slides but which you must still submitSome Notes On JDBC95-733 Internet Technologies Carnegie Mellon UniversityLab 4 Due Monday, December 10, 2001In this lab you will work with XML, JDBC, servlets and JavaMail. The idea is to complete several parts of the web application described in the figure below. This application and the figure below is from the text “XML and Java” by Maruyama, Tamura, and Uramoto, Addison-Wesley. (1) Write an HTML file called ModifyWeather.html that requests a city name and a new temperature for the city. The submit button on this HTML page should run a servlet called ModifyWeather.java. (2) Write a servlet in Java called ModifyWeather.java that accepts a post request from ModifyWeather.html. This servlet should modify the temperature associated with a particular city by calling on the services of a shared object called DBAccess.java. (3) Write a singleton class called DBAccess.java that accesses a simple Microsoft Access database. This database will consist of a single table called weather and will be found in the file weather.mdb. Its first field (City, the primary key) contains the city name and its second field (Temperature) contains the city’s temperature. The class DBAccess.java will contain the following two public methods:/* Given the city return the temperature */ public String getTemperature( String location )/* The database temperature is updated for this location */ public void setTemperature( String location, String Temperature)These methods will make use of JDBC to make queries and updates to the weather database.1 XML Mobile users PC users Http://www. xweather .com WeatherReport application WML HTML PowerWarning application Application programs XML Email notifications Registrations XML XSLT95-733 Internet Technologies Carnegie Mellon University The initial database contents will look like the following:Pittsburgh 76 San Diego 74Chicago 55New York 80London 78(4) Write a second servlet called AccessWeather.java. This servlet generates a dynamic XML document based on the contents of the database for a particular city at a particular moment. The city name is passed a request parameter. An object of class Watcher (see the course slides) will be making periodic calls on the AccessWeather servlet. A call from within the Watcher object will look exactly like the following:String weatheruri = "http://localhost:8001/servlet/AccessWeather/?City=" + URLEncoder.encode(this.city);An example string returned by this servlet would look like the following (but with no “return” characters): <?xml version="1.0" encoding="UTF-8"?> <WeatherReport> <City>Pittsburgh</City> <CurrTemp Unit = "Farenheit">2</CurrTemp> </WeatherReport> The XML document returned by this HTTP request must have the form expressed in this DTD: <?xml version="1.0" encoding="utf-8"?> <!ELEMENT WeatherReport (City, CurrTemp)> <!ELEMENT City (#PCDATA)> <!ELEMENT CurrTemp (#PCDATA)> <!ATTLIST CurrTemp Unit (Farenheit, Celsius)>Your program does not need to do validation but you should only generate XML that conforms to this DTD.(5) Write a class called Mailer that uses JavaMail to support the following method (this method will be found within each Watcher object): public void warning() { System.out.println("Sending email"); Mailer mailman = new Mailer(this.user, "[email protected]", "It's hot"); mailman.send(); }The Mailer class has a constructor with the following prototype:public Mailer(String to, String from, String msg)where to and from are both e-mail addresses.295-733 Internet Technologies Carnegie Mellon UniversitySubmission DetailsYour software will be expected to work with the software on the Week 5 slides. That is, you should have a working system and it should involve all of the files below. If you or I find errors in the code provided on the slides (not intentional on my part) then I’m afraid those errors have to be your responsibility.It’s up to you whether you rewrite all or some of the code from the slides. In either case, for grading purposes, please conform to the file names stated on this lab and mentioned in the slides. Please note that you must submit ALL these files. You must submit those from the slides as well as your own. The grader will be asked to build these back into a working system. If that task is overly difficult, you will lose points.Please submit a large envelope containing an otherwise blank floppy disk with the following files. Also, please include paper copies of ALL of these files. Your name should be written on the disk, envelope, and also at the top of each file.Files that you write============== ModifyWeather.html (HTML file) ModifyWeather.java (servlet)DBAccess.java (singleton)weather.mdb (database)AccessWeather.java (servlet producing XML)Mailer.java (a Java class that abstracts away the details of JavaMail)Files that are provided on the slides but which you must still submit===================================================Registrations.html (HTML File)PowerWarn.java (servlet that registers users)Scheduler.java (Java class that calls the watchers)Watcher.java (Java class that makes HTTP request for weather information in XML) You must modify this file so that it references AccessWeather.java with a database query rather than accessing a static file with GetWeather/Weather.xml)Some Notes On JDBCCreating an ODBC Connection•Click on the Start button.•Choose Settings, Control Panel•Double-click on ODBC Data Sources•Choose the System DSN tab•Click Add•Click on the desired driver (MSAccess)•Click on the Finish button•Enter a Data Source Name (we will call it weather)•Click on the Select button•Locate the desired file or directory•Click OKEstablish a connection from Java with DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());395-733 Internet Technologies Carnegie Mellon University connection = DriverManager.getConnection("jdbc:odbc:weather"); System.out.println("Initialization of DBAccess Singleton");Consult any good Java book to see how


View Full Document

CMU ISM 95733 - Lab

Download Lab
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lab and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lab 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?