JDBC & Servlet CSE 4504/6504 Lab.

Slides:



Advertisements
Similar presentations
Exercises of the Tutorial on Advanced Web Programming Authors: Miroslava Mitrovic Dragan Milicev Nino.
Advertisements

Java Servlets Java Server Pages (JSP)
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 24: Servlets Outline 24.1 Introduction 24.2 Servlet Overview and Architecture Interface.
Server Side Programming Common Gateway Interface (CGI): Scripts generate Web pages or other files dynamically by processing form data and returning documents.
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.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 34 Servlets.
June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 1 Lecture 10 Object Oriented Programming in Java Advanced Topics Servlets.
JDBC Overview Autumn 2001 Lecturer: C. DeJong. Relational Databases widespread use used via SQL (Structured Query Language) freely available powerful.
2/16/2004 Dynamic Content February 16, /16/2004 Assignments Due – Message of the Day Part 1 Due – Reading and Warmup Work on Message of the Day.
Java database Programming JDBC Trademarked name of a Java API that supports Java programs that access relational databases Stand for Java DataBase Connectivity.
Java Server and Servlet CS616 Team 9 Kim Doyle, Susan Kroha, Arunima Palchowdhury, Wei Xu.
Server Side Programming Web Information Systems 2012.
Abhishek Singh. Web Application: A web application is an application accessible from the web. A web application is composed of web components like Servlet,
Servlets Compiled by Dr. Billy B. L. Lim. Servlets Servlets are Java programs which are invoked to service client requests on a Web server. Servlets extend.
Servlets. Our Project 3-tier application Develop our own multi-threaded server Socket level communication.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
Examples of Using Servlets and JSP Representation and Management of Data on the Internet.
Servlets. - Java technology for Common Gateway Interface (CGI) programming. - It is a Java class that dynamically extends the function of a web server.
Java Servlets and Java Server Pages Carol Wolf Computer Science.
SKT-SSU IT Training Center Servlet and JSP. Chapter Three: Servlet Basics.
111 Java Servlets Dynamic Web Pages (Program Files) Servlets versus Java Server Pages Implementing Servlets Example: F15 Warranty Registration Tomcat Configuration.
COMP 321 Week 7. Overview HTML and HTTP Basics Dynamic Web Content ServletsMVC Tomcat in Eclipse Demonstration Lab 7-1 Introduction.
CMPUT 391 – Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems Web based Applications,
Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some.
Chapter 3 Servlet Basics. 1.Recall the Servlet Role 2.Basic Servlet Structure 3.A simple servlet that generates plain text 4.A servlet that generates.
Java + XML. Java 2 Enterprise Edition Server Side java Servlets JSP JavaBeans Web Services Database jdbc.
Introduction to JDBC Michelle Lee, Ye Wu & Jeff Offutt SWE 432 Design and Implementation of Software for the Web.
Java Servlets Outline 24.1 Introduction 24.2 Servlet Overview and Architecture Interface Servlet and the Servlet Life Cycle HttpServlet Class.
Java Servlets Lec 27. Creating a Simple Web Application in Tomcat.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
20-Nov-15introServlets.ppt Intro to servlets. 20-Nov-15introServlets.ppt typical web page – source Hello Hello.
S ERVLETS Hits Counter 21-Nov-15. S ERVLETS - H ITS C OUNTER Many times you would be interested in knowing total number of hits on a particular page of.
@2008 Huynh Ngoc Tin Chapter #2 JAVA SERVLET PRGRAMMING.
Introduction to Server-Side Web Development Introduction to Server-Side Web Development Session II: Introduction to Server-Side Web Development with Servlets.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
 2002 Prentice Hall. All rights reserved. 9.8 Multi-Tier Applications: Using JDBC from a Servlet Three-tier distributed applications –User interface –Business.
Middleware 3/29/2001 Kang, Seungwoo Lee, Jinwon. Description of Topics 1. CGI, Servlets, JSPs 2. Sessions/Cookies 3. Database Connection(JDBC, Connection.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 24: Servlets Outline 24.1 Introduction 24.2 Servlet Overview and Architecture Interface.
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.
ADO ActiveX Data Object. ActiveX Data Objects (ADO) is Microsoft’s latest database object model. The goal of ADO is to allow VB developers to use a standard.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 21 Java Servlets Wed. 11/22/00 based on material.
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
JDBC Java DataBase Connectivity. Loading the driver import java.sql.*... Class.forName("org.postgresql.Driver")‏
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.
Java Database Connectivity JDBC. Open Database Connectivity developed by Microsoft to provide interaction with databases using SQL. Use the JDBC-ODBC.
HTML III (Forms) Robin Burke ECT 270. Outline Where we are in this class Web applications HTML Forms Break Forms lab.
Programming with Java Lecture 6 Elements of a Java Servlet
Introduction to Servlets
How to Write Web Forms By Mimi Opkins.
Net-centric Computing
HTTP Servlet Overview Servlets are modules that extend request/response-oriented servers, such as Java-enabled web servers. For example, a servlet might.
Java Servlets 9/18/2018.
Distributed Computing, M. L. Liu
Java Servlets 9/21/2018.
Design and Implementation of Software for the Web
Designing Forms Lesson 10.
Servlets.
Chapter 26 Servlets.
Distributed Computing, M. L. Liu
Servlets and Java Server Pages
Handling FORM Data using Servlets
Web Search Interfaces.
Web Search Interfaces by Ray Mooney
HTML Forms 18-Apr-19.
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
Java Servlets Servlet Overview Servlets and HTML Forms Servlet Basics
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
Java Chapter 7 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

JDBC & Servlet CSE 4504/6504 Lab

Outline HTML Forms Tomcat Functions in JDBC & Servlet

HTML Forms An interface controls to collect data from the user and transmit it to server.

Element in Forms TEXT CONTROLS: PASSWORD FIELDS: TEXT AREAS: Checkbox <INPUT TYPE="TEXT" NAME="NAME" VALUE="INIT"> PASSWORD FIELDS: <INPUT TYPE="PASSWORD" NAME="PASSWORD"> TEXT AREAS: <TEXTAREA NAME="RESUME" ROWS=5 COLS=30>INPUT YOUR RESUME HERE </TEXTAREA> Checkbox <input type="checkbox" name="checkbox" checked> <input type="checkbox" name="checkbox"> Radio Button <input type="radio" name="radio" checked> <input type="radio" name="radio">

Cont. List Multilist <select name="list"> <option value="Item 1">Item 1</option> <option value="Item 2">Item 2</option> <option value="Item 3">Item 3</option> </select> Multilist <select name="multilist" size="3" multiple>

Cont. Submit Button Reset Button Image Button File <input type="submit" name="submit" value="Submit"> Reset Button <input type="reset" name="reset" value="Reset Fields"> Image Button <input type="image" name="image" src="go.gif"> File <input type="file" name="file">

Tomcat A light web server that supports servlet & JSP. It can be integrated in Apache, IIS For installation process, please refer: CS III: Lab assignment, servlet http://www.cse.msstate.edu/~cs2324/spring03/

What is JDBC & Servlet? JDBC (Java DataBase Connectivity) provides functions to access database system. Servlet enables java for CGI programs. Setup JDBC environment: Please refer: CS III, Lab assignment, JDBC http://www.cse.msstate.edu/~cs2324/spring03/ JDBC is a API provides a lot of functions to access the database system. It is used in java programming language. Servlets are modules that extend request/response-oriented servers, such as Java-enabled web servers. For example, a servlet might be responsible for taking data in an HTML order-entry form and applying the business logic used to update a company's order database. Servlets can be embedded in many different servers because the servlet API, which you use to write servlets, assumes nothing about the server's environment or protocol. Servlets have become most widely used within HTTP servers; many web servers support the Servlet API.

JDBC : Establishing a Connection loading the driver DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); making the connection String url = "jdbc:oracle:thin:@ra.msstate.edu:1521:ACAD"; Connection con = DriverManager.getConnection(url, “loginName", “Password");

Statement Create a statement Two methods of statement Statement stmt = con.createStatement(); Two methods of statement 1. executeUpdate() create, alter, drop a table Or insert, delete, update data 2. executeQuery() select

Create Table String createTableCoffees = "CREATE TABLE COFFEES " + "(COF_NAME VARCHAR(32), SUP_ID INTEGER, PRICE FLOAT, " + "SALES INTEGER, TOTAL INTEGER)"; stmt.executeUpdate(createTableCoffees);

Query Data from a Table stmt.executeQuery (“select * from customer”); ResultSet rs = stmt.executeQuery( "SELECT COF_NAME, PRICE FROM COFFEES");

Display Result Method next() Initially the cursor is above the first row of data. After call the method next(), the cursor is pointing to the first row of data. A Sample while (rs.next()) { String s = rs.getString ("COF_NAME"); float n = rs.getFloat ("PRICE"); System.out.println (s + " " + n); } References: http://java.sun.com/docs/books/tutorial/jdbc/index.html

Methods to Call a Servlet GET In html: <A HREF="/servlet/dosearch?aa=12&bb=32">Return Home</A> In html forms: <FORM ACTION=“/servlet/dosearch” METHOD=“GET”> POST <FORM ACTION=“/servlet/dosearch” METHOD=“POST”>

Interacting with Clients Handling GET and POST Requests public void doGet (HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException <a href="/servlet/getCustomers">List Customers</a> public void doPost (HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException <FORM ACTION=\"/servlet/doInsert\" METHOD=post>

Output of the Response Set the content type of the output response.setContentType ("text/html") Get parameter String bookId = request.getParameter ("bookId"); Get the output stream to write to PrintWriter out = response.getWriter(); out.println(“<HTML>”);

Servlet Program Structures import javax.servlet.*; import javax.servlet.http.*; Class must extend from class HttpServlet

A Simple Application public class SimpleServlet extends HttpServlet { // Handle the HTTP GET method by building a simple web page. public void doGet (HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { PrintWriter out; String title = "Simple Servlet Output"; // set content type and other response header fields response.setContentType("text/html"); // then write the data of the response out = response.getWriter(); out.println("<HTML><HEAD><TITLE>"); out.println (title); out.println("</TITLE></HEAD><BODY>"); out.println("<H1>" + title + "</H1>"); out.println("<P>This is output from SimpleServlet."); out.println("</BODY></HTML>"); out.close(); } You must set HTTP header data before you access the Writer or OutputStream. The HttpServletResponse class provides methods to access the header data.For example, the setContentType method sets the content type. (This header is often the only one manually set.)