Week 5 Using snoop.jsp under Jigsaw Using JavaBeans with JSP Instance variables and local variables An application using JSP, JavaBeans, and FpML An application.

Slides:



Advertisements
Similar presentations
Chapter 6 Server-side Programming: Java Servlets
Advertisements

4 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: Servlets.
JSP and Servelets.
Cookies, Sessions. Server Side Includes You can insert the content of one file into another file before the server executes it, with the require() function.
1 Servlets Based on Notes by Dave Hollinger & Ethan Cerami Also, the Online Java Tutorial by Sun.
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
Chapter 51 Scripting With JSP Elements JavaServer Pages By Xue Bai.
DT228/3 Web Development WWW and Client server model.
Objectives Ch. D - 1 At the end of this chapter students will: Know the general architecture and purpose of servlets Understand how to create a basic servlet.
Lecture 4 Java Interfaces (review of inheritance and abstract classes) The XML DOM Java Examples Homework 3.
Summer A-2000, Project Course-- Carnegie Mellon University 1 Financial Engineering Project Course.
An introduction to Java Servlet Programming
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
Financial Engineering Project Course. Lecture 3 Object Oriented Design Inheritance Abstract Base Classes Polymorphism Using XML to represent the swap.
WAP’s WML by David Boncarosky  WML Inherits From XML  WML Extends Interactivity to Cell Phones, Pagers, PDAs  Display Varies Widely From Device to Device.
Summer A-2000, Project Course-- Carnegie Mellon University 1 Financial Engineering Project Course.
Processing XML Processing XML using XSLT Processing XML documents with Java (DOM) Next week -- Processing XML documents with Java (SAX)
JSP Architecture  JSP is a simple text file consisting of HTML or XML content along with JSP elements  JSP packages define the interface for the compiled.
Java Servlets. What Are Servlets? Basically, a java program that runs on the server Basically, a java program that runs on the server Creates dynamic.
Java Enterprise Edition Java Web Development Structure of a web project Introduction to Web Applications The first project Introduction to Java Web Development.
Java Server Pages B.Ramamurthy. Topics for Discussion 8/20/20152 Inheritance and Polymorphism Develop an example for inheritance and polymorphism JSP.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
INTRODUCTION TO WEB DATABASE PROGRAMMING
1 Servlet How can a HTML page, displayed using a browser, cause a program on a server to be executed?
Java Omar Rana University of South Asia. Course Overview JAVA  C/C++ and JAVA Comparison  OOP in JAVA  Exception Handling  Streams  Graphics User.
CSC 2720 Building Web Applications Using Java Beans, Custom Tags and Tag Libraries in JSP pages.
Examples of Using Servlets and JSP Representation and Management of Data on the Internet.
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
Introduction to JSP Based on: Marty Hall, Larry Brown, Core Servlets and JavaServer Pages.
Java support for WWW Babak Esfandiari (sources: Qusay Mahmoud, Roger Impey, textbook)
CSC 2720 Building Web Applications
Java Servlets and Java Server Pages Carol Wolf Computer Science.
Li Tak Sing COMPS311F. Static attributes in Servlets Since Servlets are also Java classes, you can also use static attributes to store values that can.
Introduction to JavaServer Pages (JSP) Slides from Dr. Mark Llewellyn.
Jordan Anastasiade. All rights reserved.
Java Server Pages A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format,
Chapter 8 Script-free pages. Problem with scripting in JSP When you use scripting (declaration, scriplet, expressions) in your JSP, you actually put Java.
CSCI 6962: Server-side Design and Programming Web Services.
Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some.
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
Stanisław Osiński, 2002JSP – A technology for serving dynamic web content Java Server Pages™ A technology for serving dynamic web content Stanisław Osiński,
JAVA SERVER PAGES CREATING DYNAMIC WEB PAGES USING JAVA James Faeldon CS 119 Enterprise Systems Programming.
Website Development with PHP and MySQL Saving Data.
Introduction to JavaServer Pages. 2 JSP and Servlet Limitations of servlet  It’s inaccessible to non-programmers JSP is a complement to servlet  focuses.
Chapter 6 Server-side Programming: Java Servlets
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
Introduction to Server-Side Web Development Introduction to Server-Side Web Development Session II: Introduction to Server-Side Web Development with Servlets.
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, Responds oriented other.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
JS (Java Servlets). Internet evolution [1] The internet Internet started of as a static content dispersal and delivery mechanism, where files residing.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
WWW Programming Model. WWW Model The Internet WWW architecture provides a flexible and powerful programming model. Applications and content are presented.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 21 Java Servlets Wed. 11/22/00 based on material.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Servers- Apache Tomcat Server Server-side scripts- Java Server Pages.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Bayu Priyambadha, S.Kom. Static content  Web Server delivers contents of a file (html) 1. Browser sends request to Web Server 3. Web Server sends HTML.
S ERVLETS Form Data 19-Mar-16. F ORM P ROCESSING You must have come across many situations when you need to pass some information from your browser to.
World Wide Web has been created to share the text document across the world. In static web pages the requesting user has no ability to interact with the.
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
JSP java server pages.
Developing JavaServer Pages
Scripted Page Web App Development (Java Server Pages)
Web App vs Mobile App.
Scripted Page Web Application Development (Java Server Pages)
Presentation transcript:

Week 5 Using snoop.jsp under Jigsaw Using JavaBeans with JSP Instance variables and local variables An application using JSP, JavaBeans, and FpML An application using JSP and WML Next week – JSP details

Snoop.jsp provided with the gnujsp download produces the result.

Snoop.jsp Pg 1/11 JSP snoop page is cool JSP Snoop page Context information Server Info:

Request information Requested URL: Request method: Request URI: Request protocol: Servlet path: Snoop.jsp Pg. 2/11

Path info: Path translated: Query string: Content length: Content type: Snoop.jsp Pg. 3/11

Server name: Server port: Remote user: Remote address: Remote host: Snoop.jsp Pg. 4/11

Authorization scheme: <% Enumeration e = request.getHeaderNames(); if(e != null && e.hasMoreElements()) { %> Request headers Header: Value: <% while(e.hasMoreElements()) { String k = (String) e.nextElement(); %> Snoop.jsp Pg. 5/11

<% } %> <% } %> <% e = request.getParameterNames(); if(e != null && e.hasMoreElements()) { %> Snoop.jsp Pg. 6/11

Request parameters Parameter: Value: Multiple values: <% while(e.hasMoreElements()) { String k = (String) e.nextElement(); String val = request.getParameter(k); String vals[] = request.getParameterValues(k); %> Snoop.jsp Pg. 7/11

<% for(int i = 0; i < vals.length; i++) { if(i > 0) out.print(" "); out.print(vals[i]); } %> <% } %> <% } %> Snoop.jsp Pg. 8/11

<% e = getServletConfig().getInitParameterNames(); if(e != null && e.hasMoreElements()) { %> Init parameters Parameter: Value: <% while(e.hasMoreElements()) { String k = (String) e.nextElement(); String val = getServletConfig().getInitParameter(k); %> Snoop.jsp Pg. 9/11

<% } %> <% // Attributes available from Jserv String prefix = "org.apache.jserv."; Object attrsObj = request.getAttribute("org.apache.jserv.attribute_names"); if ( attrsObj != null && attrsObj instanceof Enumeration ) { Enumeration attrs = (Enumeration) attrsObj; %> JServ Attributes available via HttpServletRequest.getAttribute() <% while ( attrs.hasMoreElements()) { String attr = attrs.nextElement().toString(); %> Snoop.jsp Pg. 10/11

<% if ( request.getAttribute(prefix + attr) != null ) { out.println( prefix + attr + " " + request.getAttribute(prefix + attr).toString()); } else { out.println( prefix + attr + " NULL " ); } %> <% } %> <% } %> Snoop.jsp Pg. 11/11

Using JavaBeans with JSP // A javabean class found in Jigsaw/Jigsaw/Www/beans/MyInfoBean.class // The beans directory must be in the classpath. // The identifier "beans" could be any name (but in the classpath). import java.io.Serializable; public class MyInfoBean implements Serializable { private int i; public MyInfoBean() { i = 0; } public void seti(int x) { i = x; } public int geti() { return i; } }

A JSP page that uses the bean <jsp:useBean id = "oneInt" class = "MyInfoBean"> Jigsaw/Www/servlet/test1.jsp

The value is

Output of test1.jsp

Another example JSP/JavaBeans <!-- Sending two fields to a JSP from an HTML form. --> User Info Entry Form

Name: Sex(m,f):

The JSP file –useinfo1.jsp <!-- Create a bean to hold the form results and generate a response. --> <jsp:useBean id = "userInfo" class = "UserInfoBean">

Name: Sex:

// A simple bean to hold name and sex import java.io.Serializable; public class UserInfoBean implements Serializable { private String name; private String sex; public UserInfoBean() { name = null; sex = null;} public void setName(String n) { name = n; } public void setSex(String s) { if (s.equals("m")) sex = "Male"; else if(s.equals("f")) sex = "Female"; else sex = null; }

public String getSex() { return sex; } public String getName() { return name; } }

Instance Variables and Local Variables <!-- BadCounter.jsp The JSP page is turned into a servlet class when it's first requested. One instance of the servlet class is created by the servlet container. A JSP declaration places the variable in the servlet as an instance variable. The instance data is shared by each thread. Variables declared with a scripting element are local to the method and hence local to the thread. -->

<%! int globalCounter = 0; // instance data, shared by threads %> A Page WITH A COUNTER This page has been visited: times. <% int localCounter = 0; %> This counter never increases its value:

An Application using Fpml The goal is to allow internet users to work on the same document. Perhaps, in the framework of FpML, this would result in a financial agreement. The following example works but is only a sketch of a full solution.

ViewFpml.jsp

Modifyfpml.jsp

Values have been changed and saved

FixedFloatSwap.xml

A JavaBean associated with the document // A Javabean that loads an xml tree // permits data to be modified and // saves the new xml tree. import java.net.*; import java.io.*; import org.w3c.dom.*; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilder; import org.xml.sax.*; import com.sun.xml.tree.XmlDocument;

public class DOMBean implements Serializable { XmlDocument doc; double notional; double fixedRate; int numYears; int numPayments; public double getNotional() { return notional; } public double getFixedRate() { return fixedRate; } public int getNumYears() { return numYears; } public int getNumPayments() { return numPayments; } public void setChanges(String x) { System.out.println(x); saveDocument(); }

public void setNotional(double n) { notional = n; Node node = find("Notional", doc); node = node.getFirstChild(); node.setNodeValue("" + notional); } public void setFixedRate(double n) { fixedRate = n; Node node = find("Fixed_Rate", doc); node = node.getFirstChild(); node.setNodeValue("" + fixedRate); }

public void setNumYears(int n) { numYears = n; Node node = find("NumYears", doc); node = node.getFirstChild(); node.setNodeValue("" + numYears); } public void setNumPayments(int n) { numPayments = n; Node node = find("NumPayments", doc); node = node.getFirstChild(); node.setNodeValue("" + numPayments); }

public void saveDocument() { try { PrintWriter out = new PrintWriter( new BufferedWriter( new FileWriter( "c:\\Jigsaw\\Jigsaw\\Jigsaw\\Www\\fpml\\FixedFloatSwap.xml"))); doc.write(out); out.close(); } catch(IOException e) { System.out.println(e); }

public DOMBean() { // Load the document into the bean try { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); InputSource is = new InputSource( " doc = (XmlDocument) docBuilder.parse(is); extract(doc); }

catch(SAXParseException err) { System.out.println("Catching raised exception"); System.out.println("Parsing error" + ", line " + err.getLineNumber() + ", URI " + err.getSystemId()); System.out.println(" " + err.getMessage()); } catch(SAXException e) { System.out.println("Catch clause 2"); Exception x = e.getException(); ((x == null) ? e : x).printStackTrace(); } catch (Throwable t) { System.out.println("Catch clause 3"); t.printStackTrace(); }

public static void main(String a[]) { DOMBean bean = new DOMBean(); bean.setNumYears(50); bean.setChanges("Save"); }

private void extract(XmlDocument doc) { Node n = doc.getDocumentElement(); NodeList list = n.getChildNodes(); int j = list.getLength(); int k = 0; while(k < j) { switch((list.item(k)).getNodeType()) { case n.ELEMENT_NODE : if((list.item(k).getNodeName()).equals("Notional")) notional = Double.parseDouble((list.item(k).getFirstChild().getNodeValue())); if((list.item(k).getNodeName()).equals("Fixed_Rate")) fixedRate = Double.parseDouble((list.item(k).getFirstChild().getNodeValue())); if((list.item(k).getNodeName()).equals("NumYears")) numYears = Integer.parseInt((list.item(k).getFirstChild().getNodeValue())); if((list.item(k).getNodeName()).equals("NumPayments")) numPayments = Integer.parseInt((list.item(k).getFirstChild().getNodeValue())); break; } k++; }

private Node find(String x, XmlDocument doc) { Node n = doc.getDocumentElement(); NodeList list = n.getChildNodes(); int j = list.getLength(); int k = 0; while(k < j) { switch((list.item(k)).getNodeType()) { case n.ELEMENT_NODE : if((list.item(k).getNodeName()).equals(x)) return list.item(k); } k++; } return null; }

ViewFPML.JSP <!-- This JSP page allows the user to view the existing document and make changes through an HTML form. --> <jsp:useBean id = "xmlData" class = "DOMBean">

Fixed_Rate: Notional: NumYears:

NumPayments:

Notional: Fixed Rate Number of Years Number of Payments: <jsp:getProperty name = "xmlData" property = "numPayments" />

Modifyfpml.jsp <!-- This JSP file receives the data from an HTML form submission and sends the data to a JavaBean. --> <jsp:useBean id = "xmlData" class = "DOMBean">

Notional: Fixed Rate Number of Years Number of Payments:

Wireless Applications

Physical Interactions Mobile Base Station Internet request response WDP, WTP, or WSP HTTP

Wireless Communication Back-end Servers Still Must Process the Info using JSP, ASP, database, et cetera Processed Info Sent to PDA or Cell Phone (Mobile Internet Devices) Web Clipping and WML functionally similar to HTML

Web Clipping Format Similar to HTML Client Interface (designed through HTML) pre-load onto Palm Client Interface Only Accesses Internet if Information not Available Locally The Server Sends Requested Pages to Client in HTML (that palm.net automatically converts to Web Clipping format)

Web Clipping - Client My First Wireless App Please Enter The Following Information: First Name: Continued...

Web Clipping - Client Last Name:

Web Clipping - Server My First Wireless JSP You Entered the Following Information First Name: Last Name: Thanks for using our service. reflection.jsp

Web Clipping – Result

WML Not Directly Supported By Palm, but 3 rd Party Browsers Available Used In Cell Phones, Pagers, PDAs, etc. Implementations Vary Widely across Manufacturers and Models

WML – Load Page <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" " Please Enter some Info for us First: Last: Submit

WML – Server Side <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" " Here is the information you entered. First: Last: reflection2.jsp

WML - Result