Server-Side Scripting with Java Server Page, JSP.

Slides:



Advertisements
Similar presentations
Lecture plan Information retrieval (from week 11)
Advertisements

Java Classes ISYS 350. Introduction to Classes A class is the blueprint for an object. – It describes a particular type of object. – It specifies the.
Chapter 31 Basic Form-Processing Techniques JavaServer Pages By Xue Bai.
Session 6 Server-side programming - ASP. An ASP page is an HTML page interspersed with server-side code. The.ASP extension instead of.HTM denotes server-side.
Java, Access, SQL, HTML. Three-tier architecture involves: Client - Browser Server - Tomcat Database - Access - Server-side language - JSP could just.
Apache Tomcat Server – installation & use Server-side language-- use Java Server Pages Contrast Client-side languages HTML Forms Servers & Server-side.
Java database Programming JDBC Trademarked name of a Java API that supports Java programs that access relational databases Stand for Java DataBase Connectivity.
Contrast with JavaScript HTML Formsto invoke Java Server Pages Structure of Forms Query strings Java Server Pages Sent From Browser To Serverfor JSP.
Java Servlet. What is Java Servlet? A Servlet is a java based server side web technology. It is a java class that serves a client request and receives.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
Chapter 16 The World Wide Web Chapter Goals Compare and contrast the Internet and the World Wide Web Describe general Web processing Describe several.
Jaeki Song JAVA Lecture 11 Java Database Connectivity.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
Chapter 16 The World Wide Web. 2 The Web An infrastructure of information combined and the network software used to access it Web page A document that.
1 Chapter 1: Overview of Servlets and JavaSerevr Pages.
AJAX and Java ISYS 350. AJAX Asynchronous JavaScript and XML: – Related technologies: JavaScript, Document Object Model, XML, server-side script such.
Server-Side Scripting with JSP (2) ISYS 350. Java Array Examples of declaring an array: – int[] anArray = new int[10]; 10 elements index from 0 to 9 –
Server-Side Scripting with Java Server Page, JSP ISYS 350.
Java Servlets and Java Server Pages Carol Wolf Computer Science.
Active Server Pages ASP is Microsoft’s server-side script engine for dynamically-generated web pages. Most common language used is VBScript. If you use.
JDBC (Java Database Connectivity) SNU OOPSLA Lab. October 2005.
Server-Side Scripting with Java Server Page, JSP ISYS 350.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
Java Classes ISYS 350. Introduction to Classes Two basic uses of class: – 1. A class is a way to organize functions (methods) to perform calculations.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 32.1 Reviewing the Bookstore Application 32.2.
Website Development with PHP and MySQL Saving Data.
JDBC. JDBC stands for Java Data Base Connectivity. JDBC is different from ODBC in that – JDBC is written in Java (hence is platform independent, object.
JSP program that interacts with HTML form & Access Data Base.
WEB/DB1 DATABASE PROGRAMMING 3JDBC by the ASU Scholars.
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)
Jsp (Java Server Page) Is a server side program.
Java Classes ISYS 350. Introduction to Classes A class is the blueprint for an object. – It describes a particular type of object. – It specifies the.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
Server-Side Scripting with JSP (2) ISYS 350. Post Back A postback is call to the same page that the form is on. In other words, the contents of the form.
Leman Akoglu 11/11/ Fall 2009 Recitation Homework 9 Building A Web Application Phase-II School of Computer Science.
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 31.1 Reviewing the Bookstore Application 31.2.
Server-Side Scripting with PHP ISYS 475. PHP Manual Website
Server-Side Scripting with JSP (2) ISYS 350. Java Array Examples of declaring an array: – int[] anArray = new int[10]; 10 elements index from 0 to 9 –
ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
CITA 310 Section 7 Installing and Testing a Programming Environment (Textbook Chapter 7)
Java Servlet ISYS 350. What is Java Servlet? It is a java class that serves a client request. Servlets are most often used to: Process or store data that.
Database Access Using JDBC BCIS 3680 Enterprise Programming.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
Server-Side Scripting with Java Server Page, JSP.
Server-Side Scripting with Java Server Page, JSP ISYS 350.
Server-Side Scripting with Java Server Page, JSP ISYS 350.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Java Database Connectivity.
Java Database Connectivity JDBC. Open Database Connectivity developed by Microsoft to provide interaction with databases using SQL. Use the JDBC-ODBC.
Database Processing with JSP ISYS 350. Database Applications Applications Database Server Queries/Updates Results.
Java Class and Servlet ISYS 350.
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
Advanced Web Automation Using Selenium
AJAX and Java Servlet ISYS 350.
JSP Implicit Objects Implicit Objects in JSP are objects that are automatically available in JSP. request: The request object retrieves the values that.
Server-Side Scripting with Java Server Page, JSP
Server-Side Scripting with Java Server Page, JSP
AJAX and JSP ISYS 350.
Client Access, Queries, Stored Procedures, JDBC
Database Processing with JSP
Java Servlet ISYS 350.
AJAX and JSP ISYS 350.
Presentation transcript:

Server-Side Scripting with Java Server Page, JSP

Hyper Text Transfer Protocol: Request & Response Web Server Browser HTTP Request HTTP Response Web Application

Data Sent with Request and Response Request: – requested URL, cookies, queryString, data from a form, etc. Response: – Web page content in HTML code – Cookies – Etc.

Methods of request Object * getCookies() * getHeader(String name) * getMethod() * getParameter(String name) * getParameterNames() * getParameterValues(String name) * getQueryString() * getRequestURI() etc.

Use JSP to Process a Form

FORM Tag Form attribute: – Method: Preferred method is: Post – Action: Specify the URL of a program on a server or an address to which a form’s data will be submitted. Example:

Methods of response Object * setContentType() * addCookie(Cookie cookie) * addHeader(String name, String value) * containsHeader(String name) * setHeader(String name, String value) * sendRedirect(String) * sendError(int status_code)

Slide 8 Declare Variables Type variableName ; Examples int myCounter; double interestRate;

Slide 9

Compute the Sum of 2 Numbers: Example of JSP scriptlet <% String value1, value2; double n1, n2, sum; value1=request.getParameter("num1"); value2=request.getParameter("num2"); n1= Double.parseDouble(value1); n2= Double.parseDouble(value2); sum=n1+n2; out.println("The sum is:" + sum); %> Note 1: Double is an object, not “double” data type. Note 2: “out” is a variable that does not need to be declared. It is already predefined.

Writing HTML code as output <% String value1, value2; double n1, n2, sum; value1=request.getParameter("num1"); value2=request.getParameter("num2"); n1= Double.parseDouble(value1); n2= Double.parseDouble(value2); sum=n1+n2; out.println(" Value1: "); out.println(" Value2: "); out.println("The sum is: " ); %>

Using JSP Expression: String value1, value2; double n1, n2, sum; value1=request.getParameter("num1"); value2=request.getParameter("num2"); n1= Double.parseDouble(value1); n2= Double.parseDouble(value2); sum=n1+n2; %> Value1: "> Value2: "> Sum is: ">

Compute Future Value: Process form with various controls

Code Example <% String myPV, myRate, myYear,myCheckbox; myPV=request.getParameter("PV"); myRate=request.getParameter("Rate"); myYear=request.getParameter("Year"); myCheckbox=request.getParameter("testCheckbox"); double FV, PV, Rate, Year; PV=Double.parseDouble(myPV); Rate=Double.parseDouble(myRate); Year=Double.parseDouble(myYear); FV=PV*Math.pow(1+Rate,Year); out.println("FutureValue is:"+ FV); %>

Database Processing with JSP Must import java.sql using page directive: – import="java.sql.*" % Need a driver: – JDBC-ODBC Bridge: The JDBC-ODBC Bridge allows applications written in the JavaTM programming language to use the JDBCTM API with many existing ODBC drivers. – Example: String DBUrl="jdbc:odbc:MySalesDB"; Define connection object: – connection = DriverManager.getConnection(DBUrl); Define Statement object: – Statement SQLStatement = connection.createStatement(); Run SQL to create resultset: – strSQL="select * from customer where cid='" + myCid + "'"; – ResultSet rs = SQLStatement.executeQuery(strSQL);

JDBC ResultSet The rows that satisfy a particular query are called the result set. The number of rows returned in a result set can be zero or more. A user can access the data in a result set using a cursor one row at a time from top to bottom. A cursor can be thought of as a pointer to the rows of the result set that has the ability to keep track of which row is currently being accessed.

ResultSet Methods Next() : Returns true if the cursor is now positioned on a row and false if the cursor is positioned after the last row. previous() first() last()

Example: Enter CID in a box and retrieve the customer record

<% Connection connection = null; String DBUrl="jdbc:odbc:MySalesDB"; try { String myCid, strSQL, Cname, City, Rating; connection = DriverManager.getConnection(DBUrl); Statement SQLStatement = connection.createStatement(); myCid=request.getParameter("cid"); strSQL="select * from customer where cid='" + myCid + "'"; ResultSet rs = SQLStatement.executeQuery(strSQL); if (rs.next()) { Cname=rs.getString("CNAME"); City=rs.getString("CITY"); Rating=rs.getString("Rating"); rs.close(); out.println( Cname); out.println( City); out.println( Rating); } else { out.println("Customer not exist!"); rs.close(); } catch(SQLException e) { for (Throwable t :e) t.printStackTrace(); } finally { } %>

Create a CID ListBox

Select CID: <% Connection connection = null; String DBUrl="jdbc:odbc:MySalesDB"; try { String myCid, strSQL; connection = DriverManager.getConnection(DBUrl); Statement SQLStatement = connection.createStatement(); strSQL="select cid from customer;"; ResultSet rs = SQLStatement.executeQuery(strSQL); while (rs.next()) { myCid=rs.getString("cid"); out.println(" " + myCid + " "); } catch(SQLException e) { for (Throwable t :e) t.printStackTrace(); } %>