1 Pertemuan 11 Aplikasi Web dengan Servlet dan JSP Matakuliah: T0053/Web Programming Tahun: 2006 Versi: 2.

Slides:



Advertisements
Similar presentations
1 Pertemuan 1 Introduction to Web and Internet Matakuliah: T0053/Web Programming Tahun: 2006 Versi: 2.
Advertisements

Exercises of the Tutorial on Advanced Web Programming Authors: Miroslava Mitrovic Dragan Milicev Nino.
 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.
1 Pertemuan 04 Proxy/Cache Matakuliah: H0491/Praktikum Jaringan Komputer Tahun: 2005 Versi: 1/0.
1 Pertemuan 22 Radix Sort Matakuliah: T0016/Algoritma dan Pemrograman Tahun: 2005 Versi: versi 2.
1 Pertemuan 6 Elementary UDP Sockets Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.
1 Pertemuan 4 HTTP Protocol Matakuliah: T0053/Web Programming Tahun: 2006 Versi: 2.
1 Pertemuan 12 Design Pattern Matakuliah: T0053/Web Programming Tahun: 2006 Versi: 2.
Servlets. A form The HTML source Chapter 1 Please enter your name and password then press start Name: Password: In Netbeans you can graphically create.
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.
JDBC Overview Autumn 2001 Lecturer: C. DeJong. Relational Databases widespread use used via SQL (Structured Query Language) freely available powerful.
1 Pertemuan 11 QUIZ Matakuliah: J0274/Akuntansi Manajemen Tahun: 2005 Versi: 01/00.
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.
1 Pertemuan 20 Time & Condition Clauses with Future reference Matakuliah: G0134 – Grammar III Tahun: 2005 Versi: revisi 1.
Java database Programming JDBC Trademarked name of a Java API that supports Java programs that access relational databases Stand for Java DataBase Connectivity.
1 Pertemuan 8 The Object Definition Language (Lanjutan) Matakuliah: M0174/OBJECT ORIENTED DATABASE Tahun: 2005 Versi: 1/0.
Servlets. Introduction Networking –Massive, complex topic –Java networking in several packages java.net –Socket based communications View networking as.
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.
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.
Servlet and JSP Programming: An Introduction Spiros Papadimitriou
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
1 Java Database Connection (JDBC) There are many industrial-strength DBMS's commercially available in the market. Oracle, DB2, and Sybase are just a few.
Helena Pomezná, ciz034 St. skupina: L392 FEI, VŠB-TUO Ak. rok. 2002/2003 Download:
Database Management Systems 1 Oracle Programming.
Servlets Pranav Maydeo. What is a Servlet ? Servlets are modules of Java code that run in a server application to answer client requests. Servlets are.
Examples of Using Servlets and JSP Representation and Management of Data on the Internet.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 30 - Servlets: Bonus for Java Developers Outline 30.1 Introduction 30.2 Servlet Overview and.
Chapter 5 Java Servlets. Objectives Explain the nature of a servlet and its operation Use the appropriate servlet methods in a web application Code the.
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.
DataBases and SQL INFSY 547 Spring Course Wrap Up April 12: Complete Work on Servlets Review of Team Projects Close of Portfolio Work April 19:
CS4273: Distributed System Technologies and Programming I Lecture 9: Java Servlets.
Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some.
MDCFUG Is Java in Your Future? Tyler Williams Principal dataTerrace
JDBC Java and Databases, including Postgress. JDBC l Developed by Industry leaders l Three main goals: –JDBC should be an SQL-level API –JDBC should capitalize.
Java Servlets Outline 24.1 Introduction 24.2 Servlet Overview and Architecture Interface Servlet and the Servlet Life Cycle HttpServlet Class.
Mark Dixon 1 09 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 32.1 Reviewing the Bookstore Application 32.2.
Java Servlets & Java Server Pages Lecture July 2013.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 31.1 Reviewing the Bookstore Application 31.2.
 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.
Mark Dixon 1 11 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
Vakgroep Informatietechnologie – Onderzoeksgroep (naam) Web Centric Design of Distributed Software.
JAVA DATABASE OOP Praktek dengan Java Miswar,S.st Sumber : Eddy Muntina Dharma,ST,MT.
Web Programming Assistant Professor Xiaozhong Liu
April 20023CSG11 Electronic Commerce Java (2) John Wordsworth Department of Computer Science The University of Reading Room 129,
Java Database Connectivity JDBC. Open Database Connectivity developed by Microsoft to provide interaction with databases using SQL. Use the JDBC-ODBC.
CS 562 Advanced Java and Internet Application Computer Warehouse Web Application By Team Alpha :-  Puja Mehta (102163)  Mona Nagpure (102147)
CS320 Web and Internet Programming Database Access with JDBC Chengyu Sun California State University, Los Angeles.
Servlets Outline 1 Introduction 2 Servlet Overview and Architecture 2.1 Interface Servlet and the Servlet Life Cycle 2.2 HttpServlet Class 2.3 HttpServletRequest.
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
Pertemuan 04 Proxy/Cache
Pertemuan 20 The Business Views of the Technology Architecture
J2EE (Enterprise Programing)
Servlets Outline Introduction Servlet Overview and Architecture Interface Servlet and the Servlet Life Cycle HttpServlet Class HttpServletRequest.
Pertemuan 22 The Business Views of the Technology Architecture
PERTEMUAN 2.
JDBC & Servlet CSE 4504/6504 Lab.
CS320 Web and Internet Programming Database Access with JDBC
HW#4 Making Simple BBS Using JDBC
Prof: Dr. Shu-Ching Chen TA: Sheng Guan
COP 4610L: Applications in the Enterprise Spring 2005
Java Servlets Servlet Overview Servlets and HTML Forms Servlet Basics
CS3220 Web and Internet Programming Database Access with JDBC
CS3220 Web and Internet Programming Database Access with JDBC
Presentation transcript:

1 Pertemuan 11 Aplikasi Web dengan Servlet dan JSP Matakuliah: T0053/Web Programming Tahun: 2006 Versi: 2

2 Learning Outcomes Pada akhir pertemuan ini, diharapkan mahasiswa akan mampu : Menjelaskan Teknik membangun aplikasi web berbasis Servlet dan JSP yang terhubung ke database Membuat aplikasi web yang lebih komplek menggunakan Servlet dan JSP yang terkoneksi ke database Menggunakan session & cookie

3 Outline Materi Aplikasi web dengan Servlet dan JSP Aplikasi web menggunakan JDBC tingkat lanjut

4 Advanced Servlet

5 Codes Guest Book Form Guest Book Binus <FORM ACTION= /GuestBookServlet METHOD=POST> address: First Name: ….

6 Servlet import java.io.*;import javax.servlet.*;import javax.servlet.http.*; import java.util.*;import java.sql.*; public class GuestBookServlet extends HttpServlet { private Statement statement = null; private Connection connection = null; private String URL = "jdbc:odbc:Kopi"; public void init( ServletConfig config )throws ServletException { super.init( config ); try { Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" ); connection = DriverManager.getConnection( URL, "sa", "" ); } catch ( Exception e ) { e.printStackTrace();connection = null; }} public void doPost( HttpServletRequest req,HttpServletResponse res ) throws ServletException, IOException { String , firstName, lastName, company, ….

7 Servlet public void doPost( HttpServletRequest req,HttpServletResponse res ) throws ServletException, IOException { String , firstName, lastName, company, snailmailList, cppList, javaList, vbList, iwwwList; = req.getParameter( " " ); firstName = req.getParameter( "FirstName" ); lastName = req.getParameter( "LastName" ); company = req.getParameter( "Company" ); snailmailList = req.getParameter( "mail" ); cppList = req.getParameter( "c_cpp" ); javaList = req.getParameter( "java" ); vbList = req.getParameter( "vb" ); iwwwList = req.getParameter( "iwww" ); PrintWriter output = res.getWriter(); res.setContentType( "text/html" ); …..

8 Codes private boolean insertIntoDB( String stringtoinsert ) { try { statement = connection.createStatement(); statement.execute( "INSERT INTO GuestBook values (" + stringtoinsert + ");" ); statement.close(); } catch ( Exception e ) { System.err.println( "ERROR: bermasalah menambahkan data baru" ); e.printStackTrace(); return false; } return true; } public void destroy() { try { connection.close(); } catch( Exception e ) { System.err.println( "bermasalah menutup database" ); } }}

9 Sample Web

10 Display Data Daftar Programmer No nama Deskripsi Aksi <% Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection ("jdbc:odbc:kopi","sa",“password"); Statement stmt = con.createStatement (); ResultSet rst = stmt.executeQuery ("Select * from programmer");

11 Display Data while(rst.next()) //baca data { int no=rst.getInt("no"); String nama=rst.getString("nama"); String deskripsi=rst.getString("deskripsi"); out.print (" "+no+" "); out.print (" "+nama+" "); out.print (" "+deskripsi+" "); out.print (" Rubah Data"); out.print (" | Hapus Data "); out.println (" "); } stmt.close(); con.close();

12 Add Data

13 Add Data <% String nama=request.getParameter ("nama"); String ganti=request.getParameter ("TextGanti"); String sql="insert into programmer (nama,deskripsi) " + "values"('"+ nama + "','" + ganti+ "')"; Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection ("jdbc:odbc:kopi","sa","mautauaja"); Statement stmt = con.createStatement (); stmt.executeUpdate(sql); stmt.close(); con.close(); %>

14 Edit Data

15 Edit Data String kunci=request.getQueryString(); String sql= "Select * from programmer where programmer.no = " + kunci; Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection ("jdbc:odbc:Trisakti","sa",“password"); Statement stmt = con.createStatement (); ResultSet rs=stmt.executeQuery(sql); rs.next(); %> Silahkan Update data ");%>

16 Save Data <% String kunci=request.getParameter ("kunci"); String nama=request.getParameter("nama"); String ganti=request.getParameter ("TextGanti"); String sql ="update programmer set nama='" + nama + "', deskripsi='" + ganti+"' where no="+ kunci; Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection ("jdbc:odbc:Trisakti","",""); Statement stmt = con.createStatement (); stmt.executeUpdate(sql); stmt.close(); con.close(); %>

17 Session & Cookie When you are working with an application, you open it, do some changes and then you close it. This is much like a Session. The computer knows who you are. It knows when you start the application and when you end. But on the internet there is one problem: the web server does not know who you are and what you do because the HTTP address doesn't maintain state. Java solves this problem by creating a unique cookie for each user. The cookie is sent to the client and it contains information that identifies the user. This interface is called the Session object.

18 Cookie //buat session session.setAttribute("idk", idk); //baca session String idk=(String)session.getAttribute("idk"); Cookie[] cookies = request.getCookies(); for (int i = 0; i < cookies.length; i++) { Cookie c = cookies[i]; String name = c.getName(); String value = c.getValue(); out.println(name + " = " + value);

19 References Deithel, “Java How To Program”, 5 th ed, 2006 Widodo Budiharto, “Panduan Lengkap Pemrograman J2EE”, Andi Offset Yogyakarta,