Web Development in Java Andrew Simpson. Overview Background Language Details Java Server Pages (JSP) Servlets Database Connectivity (JDBC) Samples and.

Slides:



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

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.
JavaServerPages Some examples. About JSP Java server pages are a combination of html (or xml), java code appearing within tagged regions, and structures.
Java Servlet & JSP © copyright 2005 SNU OOPSLA Lab.
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.
CSE 190: Internet E-Commerce Lecture 7. HTML Templates Designed to separate server side logic from HTML presentation Key features –Escapes from HTML into.
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
JSP Java Server Pages Reference:
Introduction to Servlet & JSP
Comp2513 Java Servlet Basics Daniel L. Silver, Ph.D.
Java Server and Servlet CS616 Team 9 Kim Doyle, Susan Kroha, Arunima Palchowdhury, Wei Xu.
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.
Chapter 4 Servlets Concept of Servlets (What, Why, and How) Servlet API Third-party tools to run servlets Examples of Using Servlets HTML tag with GET.
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.
CSCI 6962: Server-side Design and Programming History and Background.
Java Servlets and JSP.
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.
Server-side Technologies
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
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 support for WWW Babak Esfandiari (sources: Qusay Mahmoud, Roger Impey, textbook)
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
111 Java Servlets Dynamic Web Pages (Program Files) Servlets versus Java Server Pages Implementing Servlets Example: F15 Warranty Registration Tomcat Configuration.
 Embeds Java code  In HTML tags  When used well  Simple way to generate dynamic web-pages  When misused (complex embedded Java)  Terribly messy.
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.
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,
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.
MDCFUG Is Java in Your Future? Tyler Williams Principal dataTerrace
Java Servlets. Servlets When we run small Java programs within a browser these are referred to as Applets... And when we run small Java programs within.
Java Servlets & Java Server Pages Lecture July 2013.
JSP Presented by K.Venkata Ratnam HOD MCA (Dept) Newton’s Institute of Engineering.
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
Chapter 2 Web app architecture. High-level web app architecture  When a client request coming in and needs servlet to serve dynamic web content, what.
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.
A seminar on j2ee by saritha. s. What is J2EE J2EE (Java 2 Platform, Enterprise Edition) is a Java platform designed for the mainframe-scale computing.
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
Java Servlet API CGI / HTTP Concepts Java Servlet API.
JavaServer Page by Antonio Ko. Overview ► Introduction ► What is a servlet? ► What can servlets do? ► Servlets Vs JSP ► Syntax ► Samples ► JavaBean ►
Java Servlets and Java Server Pages Norman White Stern School of Business.
JSP Pages. What and Why of JSP? JSP = Java code imbedded in HTML or XML –Static portion of the page is HTML –Dynamic portion is Java Easy way to develop.
Middleware 3/29/2001 Kang, Seungwoo Lee, Jinwon. Description of Topics 1. CGI, Servlets, JSPs 2. Sessions/Cookies 3. Database Connection(JDBC, Connection.
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.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 21 Java Servlets Wed. 11/22/00 based on material.
Java Servlets and Java Server Pages
Chapter 6 Chapter 6 Server Side Programming (JSP) Part 1 1 (IS 203) WebProgramming (IS 203) Web Programming.
How CGI and Java Servlets are Run By David Stein 14 November 2006.
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.
Creative Commons Attribution- NonCommercial-ShareAlike 2.5 License Sakai Programmer's Café Sakai Montreal CRIM Workshop Comparative Display Technologies.
CS 562 Advanced Java and Internet Application Computer Warehouse Web Application By Team Alpha :-  Puja Mehta (102163)  Mona Nagpure (102147)
Speaker Name Speaker Title Speaker Title Oracle Corporation Olivier Le Diouris Principal Product Manager Oracle Corporation Building Servlet and JSP Applications.
CS122B: Projects in Databases and Web Applications Spring 2017
Introduction to Servlets
Introduction Servlets and JSP
Servlet Fudamentals.
Course Outcomes of Advanced Java Programming AJP (17625, C603)
Servlets Hits Counter 20-Jul-18.
Servlets and JSP 20-Nov-18 servletsJSP.ppt.
CS122B: Projects in Databases and Web Applications Spring 2018
Basic servlet structure
Presentation transcript:

Web Development in Java Andrew Simpson

Overview Background Language Details Java Server Pages (JSP) Servlets Database Connectivity (JDBC) Samples and Application

Background Java is a compiled language Can be server side or client side, servlets or applets Java has many applications outside of web development Java is syntactically very similar to C++ and other compiled languages

Typical Java Code import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloWorld extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println(" "); out.println(" Hello World! "); out.println(" "); out.println(" Hello World! "); out.println(" "); }

Primitive Data Types KeywordDescriptionSize/Format ByteByte-length integer8-bit 2’s complement ShortShort integer16-bit 2’s complement IntInteger32-bit 2’s complement LongLong integer64-bit 2’s complement FloatSingle precision float32-bit IEEE 754 DoubleDouble precision float64-bit IEEE 754 CharA single character16 bit Unicode char BooleanA boolean valueTrue or false

Java’s Tools Similar to the stdlib in C++, Java has many common data types and other procedures already implemented AbstractCollection, AbstractList, ArrayList, Array, BitSet, Calendar, Collections, Currency, Date, Dictionary, HashMap, HashSet, LinkedHashMap, Properties, Stack, StringTokenizer, Timer, TreeMap, TreeSet, Vector

Comparisons The usual operators work on the primitive data types Class defined comparisons are required for all other data types Comparator lets the programmer define their own criteria Comparator can be defined for Java to sort different structures automatically

Error Handling Try/Catch Blocks Functions can throw exceptions Public int foo(int x, char y) thows ServletException { if (x < 0 ) throw new ServletException(“X is negative”); if (y >= ‘a’ && y <= ‘z’) throw new ServletException(“Y is not a lower case letter”); return 1; }

Java Server Pages (JSP) Similar to Perl in that it is not compiled at first, but rather compiled on the server Can contain static HTML/XML components Uses “special” JSP tags Optionally can have snippets of Java in the language called scriptlets

JSP Translation

JSP Syntax Embedding JAVA into static content Creating new dynamic tags to do embedding Embedding static content into JAVA There are multiple styles that a JSP translator recognizes to writing a JSP

Embedding Java Exp Result \${1} ${1} \${1 + 2} ${1 + 2} \${ } ${ } ExpResult ${1}1 ${1+2}3 ${ }3.5

Using Dynamic Tags JSP 2.0 Examples - Hello World SimpleTag Handler JSP 2.0 Examples - Hello World SimpleTag Handler This tag handler simply echos "Hello, World!" It's an example of a very basic SimpleTag handler with no body. Result: Result: Hello, world!

Tag Library (Pseudo class) package jsp2.examples.simpletag; import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.SimpleTagSupport; import java.io.IOException; /** * SimpleTag handler that prints "Hello, world!" */ public class HelloWorldSimpleTag extends SimpleTagSupport { public void doTag() throws JspException, IOException { getJspContext().getOut().write( "Hello, world!" ); }

Embedding HTML Refer to embedhtml.jsp file for example This is the more common form that is actually used This form is dominated mostly by scripting HTML is a quick and easy output method far less verbose than trying to use a servlet to write out the entire output stream

Model for Server Handling

Request Handling

General Application Flow

Using A Java Servlet Compiled to form a class before being put on the server Does not allow embedded code Functions very much like a class in C++ Has several built in functions specific to web development that are very useful

JSP vs. Servlets JSP is really just an extension of the Servlet API Servlets should be used as an extension of web server technology, specialized controller components, database validation. JSP handles text while Servlets can interface other programs

Servlets and HTML Forms Post vs. Get Methods Built in handling doPost and doGet Good for taking in information in servlet request, processing it, generating a servlet response and returning it back to the browser Notion that server always passes a separate class object for Requests and Responses between pages which carry a persisting Session object in many cases.

Session Object for Requests

General Servlet Info Similar to C++ class Member variables/functions Private and Public options Usually extension of some other class, new class inherits functions of extended class

JDBC Java.sql.* package serves as that java ODBC equivalent Basic Methods: Driver, DriverManager, Connection, Statement, PreparedStatement, Callable Statement, ResultSet Statements allow JDBC to execute SQL commands

Starting a Database Connect by passing a driver to the DriverManager Obtain a Connection with URL, username and password Pass SQL commands with a Statement Examine ResultSet if applicable Close the database View dbsamp.jsp for startup sequence and simple query

Data Navigation and Extraction Result.next(); Result.getInt(1); Result.getString(“Customer”); Result.getDate(4); (java.sql.Date not java.util.Date)

Prepared Statements pstmtU = con.prepareStatement( "UPDATE myTable SET myStringColumn = ? " + "WHERE myIntColumn = ?" ); pstmtU.setString( 1, "myString" ); pstmtU.setInt( 2, 1024 ); pstmtU.executeUpdate();

Conclusion This is a really general fast overview to outline the overarching concepts Refer to for lots of good documentation, API descriptionshttp://java.sun.com Excellent collection of basic tutorials at, I will now go over a real example of a Java web based application