Presentation is loading. Please wait.

Presentation is loading. Please wait.

Links JSP & Komponenten DB Daten Zugriff Anwendungs Logik Daten Präsentation WEB Designer Java Entwickler.

Similar presentations


Presentation on theme: "Links JSP & Komponenten DB Daten Zugriff Anwendungs Logik Daten Präsentation WEB Designer Java Entwickler."— Presentation transcript:

1 Links

2 JSP & Komponenten DB Daten Zugriff Anwendungs Logik Daten Präsentation WEB Designer Java Entwickler

3 Actions Steuerung des Kontrollfluss zwischen den Seiten. Zusammenspiel mit Beans Spezifikation für Applets.

4 Forward /> Request Response Original Page Forwarded Page Request

5 Anwendungen forward 1.Parameterübergabe 2. Kontrollfluss

6 Include Request Response Original Page Included Page Request Response

7 Action vs. Direktive Direktive Im Moment der Seitengenerierung wird der Inhalt eingefügt. Action Der Request wird direkt auf die neue Seite umgeleitet und der Response wird wieder zurückgeleitet.

8 Problematik Servlets streng definiert pure Java mit viel Dokument-Quellcode oft unübersichtlich JSP Schwammige Spezifikationen, Durchmischung zweier Technologien Mit viel Java-Code oft unübersichtlich JSP

9 Java Beans

10

11 Java Beans, Part 1 (java.sun.com) Support for introspection allowing a builder tool to analyze how a bean works. Support for customization allowing a user to alter the appearance and behavior of a bean. Support for events allowing beans to fire events, and informing builder tools about both the events they can fire and the events they can handle. Support for properties allowing beans to be manipulated programatically, as well as to support the customization mentioned above. Support for persistence allowing beans that have been customized in an application builder to have their state saved and restored. Typically persistence is used with an application builder's save and load menu commands to restore any work that has gone into constructing an application.

12 heloworld Bean package jspcr; import java.io.*; public class heloworldbean implements Serializable { private String message; public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public String getCount10() { String s; s=""; for (int i=0;i < 10 ; i++ ) { s += i+" "; } return s; }

13 helloworld bean jsp helloworld Helloworld JSP hier kommt die Meldung: und nun auf 10:

14 Web Service: Flugwetter 1. Aktuelle Daten 2. Web Architektur 3. Logik (Business Objekt) 4. Implementierung Bean Präsentation (JSP, CSS, HTML)

15 Daten aus dem WEB

16 weather observation Architektur portal.jsp Cookie? Airport- Selection.html SetAirport- Code.jsp sendRedirect style.css

17 Business Logic getAirportCode() setAirportCode(String airportCode) getLocation() getTemperature() getTime() getURL() Hilfsmethoden load(InputStream stream) loadFromURL(URL url) load(InputStream stream) parseLocation(String line) parseTime(String line) parseTemperature (String line)

18 Bean: Weather package jspcr.beans.weather; import java.io.*; import java.net.*; import java.text.*; import java.util.*; public class Observation implements Serializable { private static final String BASEURL = "http://weather.noaa.gov/weather/current"; private static final SimpleDateFormat DATEFMT = new SimpleDateFormat("MMM dd, yyyy - hh:mm aa zzz"); private String airportCode; private String location; private Date time; private Double temperature;

19 Bean Methoden // Bean accessor methods public String getAirportCode() { return airportCode; } public void setAirportCode(String airportCode) throws IOException { this.airportCode = airportCode; loadFromURL(getURL()); } public String getLocation() { return location; } protected void setLocation(String location) { this.location = location; }

20 Load public URL getURL() throws MalformedURLException { StringBuffer sb = new StringBuffer(); sb.append(BASEURL); sb.append("/K"); sb.append(airportCode.toUpperCase()); sb.append(".html"); return new URL(sb.toString()); } protected void loadFromURL(URL url) throws IOException { load(url.openStream()); } protected void load(InputStream stream) throws IOException { location = null; time = null; temperature = null; BufferedReader in = new BufferedReader( new InputStreamReader(stream)); for (;;) { // while(true) String line = in.readLine(); if (line == null) break; if (location == null) parseLocation(line); if (time == null) parseTime(line); if (temperature == null) parseTemperature(line); } in.close(); }

21 Parse Temperature protected void parseTemperature(String line) { final String TOKEN1 = "("; final String TOKEN2 = "C)"; int q = line.lastIndexOf(TOKEN2); if (q != -1) { int p = line.lastIndexOf(TOKEN1); if (p != -1) { p += TOKEN1.length(); String token = line.substring(p, q).trim(); try { setTemperature(Double.parseDouble(token)); } catch (NumberFormatException e) { e.printStackTrace(); }

22 statische Dateien style.css.whiteOnBlue,.blueOnWhite { font-family: Verdana; font-size: 9pt; text-decoration: none; }.whiteOnBlue { background-color: #005A9C; color: #FFFFFF; }.blueOnWhite { background-color: #FFFFFF; color: #005A9C; } AirportSelection.html Airport Selection Select airport: Charlotte Douglas International Airport Dallas Fort Worth International Airport Denver International Airport Kennedy International Airport Klamath Falls International Airport La Guardia Airport Lake Tahoe Airport Los Angeles International Airport Newark International Airport Newburgh Stewart Airport Roswell Industrial Air Center Airport Santa Fe County Municpal Airport Salt Lake City International Airport San Francisco International Airport Seattle Tacoma International Airport Wenatchee Pangborn Memorial Airport Yakima Air Terminal

23 setAirPort Code.jsp <% String airportCode = request.getParameter("airportCode"); if (airportCode != null) { Cookie cookie = new Cookie("airportCode", airportCode); final int ONE_YEAR = 60 * 60 * 24 * 365; cookie.setMaxAge(ONE_YEAR); response.addCookie(cookie); } response.sendRedirect("Portal.jsp"); %>

24 Portal.jps LyricNote Portal <% String airportCode = "RDU"; Cookie[] cookies = request.getCookies(); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; if (cookie.getName().equals("airportCode")) { airportCode = cookie.getValue(); break; } %>

25 Portal.jps (II) Weather C° Select City

26 Praktikum JSP – Java Bean Anwendung 1.Begrüssungsseite (jsp) 2.Portalseite (jsp) 3.Auswahl (html, jsp) 4.Bean Bsp.: (Schweizer Wetter, Börsenkurse, 5-10 Bahnverbindungen mit aktuellen Zeiten)


Download ppt "Links JSP & Komponenten DB Daten Zugriff Anwendungs Logik Daten Präsentation WEB Designer Java Entwickler."

Similar presentations


Ads by Google