CF and JSP/Servlets Developed originally by Robi Sen For the CF UnderGround II Seminar, Apr 2001 Edited and enhanced by Charlie Arehart (Robi had an emergency.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

Java Script Session1 INTRODUCTION.
Java Server Pages (JSP)
Apache Struts Technology
1 Database Driven Web Application Clients Application Servers including web servers Database Server Traditional client-server (2-tier architecture): client:
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
Web Applications Development Using Coldbox Platform Eddie Johnston.
Using JavaServer Pages Harry R. Erwin, PhD CIT304/CSE301.
Server-Side vs. Client-Side Scripting Languages
JSP: JavaServer Pages Juan Cruz Kevin Hessels Ian Moon.
WEB1P servintro1 Introduction to servlets and JSP Dr Jim Briggs.
15 Chapter 15 Web Database Development Database Systems: Design, Implementation, and Management, Fifth Edition, Rob and Coronel.
28/1/2001 Seminar in Databases in the Internet Environment Introduction to J ava S erver P ages technology by Naomi Chen.
Fast Track to ColdFusion 9. Getting Started with ColdFusion Understanding Dynamic Web Pages ColdFusion Benchmark Introducing the ColdFusion Language Introducing.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic Server Side Web Technologies: Part 2.
Week 2 IBS 685. Static Page Architecture The user requests the page by typing a URL in a browser The Browser requests the page from the Web Server The.
DT228/3 Web Development JSP: Directives and Scripting elements.
Why ColdFusion is incorporating JAVA Servlets Overview Overview of generic problem Detailed View of ColdFusion Applications of ColdFusion on Co-Op Future.
1 CS6320 – Why Servlets? L. Grewe 2 What is a Servlet? Servlets are Java programs that can be run dynamically from a Web Server Servlets are Java programs.
Java Server Pages Russell Beale. What are Java Server Pages? Separates content from presentation Good to use when lots of HTML to be presented to user,
Java Server Team 8. Overview What is a Java Server? History Architecture Advantages Disadvantages Current Technologies Conclusion.
Introduction to Servlet & JSP
JavaServer Pages TM Introduce by
Web-Enabling the Warehouse Chapter 16. Benefits of Web-Enabling a Data Warehouse Better-informed decision making Lower costs of deployment and management.
Introduction Servlets and JSP Celsina Bignoli
Java Server Pages (JSP) Presented by: Ananth Prasad & Alex Ivanov May 10, 2001.
Overview of JSP Technology. The need of JSP With servlets, it is easy to – Read form data – Read HTTP request headers – Set HTTP status codes and response.
Server Side Scripting Norman White. Where do we do processing? Client side – Javascript (embed code in html) – Java applets (send java program to run.
1 Web Database Processing. Web Database Applications Static Report Publishing a report is prepared from a database application and exported to HTML DB.
Java Server Pages CS-422. What are JSPs A logical evolution of java servlets –most servlets dynamically create HTML and integrate it with some computational.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
AIT 616 Fall 2002 PHP. AIT 616 Fall 2002 PHP  Special scripting language used to dynamically generate web documents  Open source – Free!!!  Performs.
Introduction to ColdFusion Penn State Web 2001 Conference Brian Panulla Elmwood Media Group, LLC.
PHP TUTORIAL. HISTORY OF PHP  PHP as it's known today is actually the successor to a product named PHP/FI.  Created in 1994 by Rasmus Lerdorf, the very.
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 10 Overview of JSP Technology. Understanding the need for JSP JSP technology enables to mix regular, static HTML with dynamically generated content.
Introduction to ColdFusion Yu Fu 2003 MEC Candidate.
JAVA SERVER PAGES CREATING DYNAMIC WEB PAGES USING JAVA James Faeldon CS 119 Enterprise Systems Programming.
JSTL Lec Umair©2006, All rights reserved JSTL (ni) Acronym of  JavaServer Pages Standard Tag Library JSTL (like JSP) is a specification, not an.
Chapter 6 Server-side Programming: Java Servlets
CF Pest Control By Shlomy Gantz President, BlueBrick Inc. Presented by Sandra Clark
MC365 Application Servers, Servlets, and Java Server Pages (JSP’s): Tomcat.
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
CF101: Welcome to ColdFusion Simon Horwith CTO, Etrilogy Ltd.
ASP (Active Server Pages) by Bülent & Resul. Presentation Outline Introduction What is an ASP file? How does ASP work? What can ASP do? Differences Between.
Java Servlets and Java Server Pages Norman White Stern School of Business.
An Introduction to JavaServer™ Pages Prepared by Nicole Swan.
CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
STRUCTURE OF JSP PRESENTED BY: SIDDHARTHA SINGH ( ) SOMYA SHRIVASTAV ( ) SONAM JINDAL ( )
1) PHP – Personal Home Page Scripting Language 2) JavaScript.
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
Chapter 6 Chapter 6 Server Side Programming (JSP) Part 1 1 (IS 203) WebProgramming (IS 203) Web Programming.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
 Java Server Pages (JSP) By Offir Golan. What is JSP?  A technology that allows for the creation of dynamically generated web pages based on HTML, XML,
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.
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
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.
A S P. Outline  The introduction of ASP  Why we choose ASP  How ASP works  Basic syntax rule of ASP  ASP’S object model  Limitations of ASP  Summary.
ASP Mr. Baha & Dr.Husam Osta  What is ASP?  Internet Information Services  How Does ASP Differ from HTML?  What can ASP do for you?  ASP Basic.
PHP using MySQL Database for Web Development (part II)
Introduction Servlets and JSP
Introduction to JSP Liu Haibin 12/09/2018.
MSIS 655 Advanced Business Applications Programming
Introduction to Servlets
Intro to Programming (in JavaScript)
Presentation transcript:

CF and JSP/Servlets Developed originally by Robi Sen For the CF UnderGround II Seminar, Apr 2001 Edited and enhanced by Charlie Arehart (Robi had an emergency and couldn’t make it)

Topics Covered Overview JSP/Servlets Comparison of CF and JSP Tags Variables Application Scope Conditional Processing Reusing Common Code Sessions Database Access JSP/Servlet Engine, Tool Vendors Leveraging Java in CF Today Learning More

What are they? JSP/Java Servlets Servlets Comparable to CGI/ISAPI/NSAPI programming, in Java vs Perl Java class that dynamically extends the function of a Web Server Handle HTTP requests and generate HTTP responses JSP Tag-based scripting and page-template interface to Java development, a la CF High level abstraction language to servlet standard

Server Process for JSP

What CF has over JSP ColdFusion offers: Faster learning curve More features in language out of the box (i.e. cftransaction, cfhttp, cfftp, cached queries, queries of queries) Greater abstraction, high productivity Greater maturity as web application

What JSP over CF JSP offers: Platform Agnostic(Write Once Run Anywhere) Scalability and Robustness Performance and power Access to Enterprise Technologies Manageability Standardization Massive adoption and developer community

JSP VS CF As well as: Greater acceptance Better reputation More developer resources And being based on Java Object oriented Many libraries

Underlying JSP/Servlets is Java Not really appropriate to see JSP as “just an alternative scripting environment” Yes, pretty easy to compare simple things Really need to understand Java to use effectively And to fully leverage the power it brings Underlying JSP is servlets Some things easier to do in one or the other JSP generally favored when creating lots of HTML on a page JSP can be seen as your entrée to servlets

Exploring JSP vs. CF Tags CF Begin with CF (e.g., ) Most have closing tags (e.g., HTML code JSP Begin with Contain Java code, expressions, directives, etc.

CF Tags vs. JSP Tags May help to consider comparing CF and JSP for performing common tasks  (set the output MIME type) vs (turn on session-state management)

Where Files Are Stored Will depend on Java App Server I’m using Jrun, which supports multiple servers, and multiple applications—doing demo in “Demo” server Files stored at: D:\Program Files\Allaire\JRun\servers\default\demo-app\jsp JRUN sets up web server mapping to find files at: Have set up mapping in Studio to enable browse

Variables Variable Type (string, integer, etc.) Type-less in ColdFusion Strongly typed in JAVA Case Sensitivity Ignored in CF Enforced in JSP

Defining Variables CF Hello #firstName# JSP Hello

Defining Variables Can also perform “pure” java statements within JSP, as a “scriptlet” which can be useful in some situations though not particularly so, here

Conditional Processing HTML and CFML tags executed if expression is true HTML and CFML tags executed if expression is false if/else in pure Java (servlet, class, scriptlet) <% if(expression) { // Java code to execute if expression is true } else { // Java code to execute if expression is false } %>

Conditional Processing if/else in JSP HTML and JSP tags executed if expression is true HTML and JSP tags executed if expression is false

Conditional Processing Conditional Expressions in CF/JSP Really about CF vs Java expressions, as in: IS vs == or.equals() IS NOT vs !=

Conditional Processing #i# “for” loop in pure Java <% for(int i=1; i<=10; i++) { out.println(i + “ ”); } %>

Conditional Processing “for” loop in JSP

Reusing Common Code CF JSP or More like CF custom tag call Goes to other page, executes, and returns Passes request object to called page

Redirection CF Java <% RequestDispatcher aDispatcher = request.getRequestDispatcher(“/Templates/hea der.jsp”); aDispatcher.include(request, response); %> JSP

Comments CF Java JSP

Session State Maintenance CF Cookies Application.cfm Application variables Session variables

Application Scope Application Variable Shared among all users of application #Application.myVariable# Application object in JSP Shared among all users of application <% application.setAttribute(“myVariable”, “somevalue”); out.println(application.getAttribute(“myVariable”) ); %>

Application Scope ServletContext object Shared among all users of servlet <% getServletContext().setAttribute(“myVar iable”, “somevalue”); getServletContext().getAttribute(“myVaria ble”); %>

Session State Maintenance CF “session.” variables Servlet HttpSession object <% HttpSession aSession = request.getSession(); aSession.setAttribute(“name”, “John Doe”); %> JSP session object is an instance of the HttpSession object.

Database Access ODBC Standard database access method Inserts a middle layer (driver) between the database and the application JDBC (Java Database Connectivity) Based on ODBC Allows access to any tabular data source from the Java programming language

Database Access: In CF Use CF Administrator to set the DataSource Query the database using select firstname, lastname from mytable where id = #variables.anID# Accessing the data from the ResultSet #myquery.firstname# #myquery.lastname#

Database Access: In CF Displaying the ResultSet One Row The name is #myquery.firstname# #myquery.lastname# Many Rows The name is #myquery.firstname# #myquery.lastname#

Database Access: In Java Set the DataSource using a GUI tool (e.g., Jrun Mgt Console ) In “default server” Edit “jdbc data sources” Click edit to create a new one If already defined on server in odbc Enter its name, in “name” (ie, cfexamples) Enter sun.jdbc.odbc.JdbcOdbcDriver for “driver” Enter “jdbc:odbc:cfexamples” for url Enter any other needed info (userid, password) “Update”, then “test”

Database Access: In Java In page, import needed libraries Obtain a reference to the DataSource using JNDI <% InitialContext aContext = new InitialContext(); DataSource myDataSource = (DataSource) aContext.lookup(“java:comp/env/jdbc/cfexampl es”);%>

Database Access: In Java Call the DataSource method getConnection() to establish a connection Connection con = myDataSource.getConnection();

Database Access: In Java Create/Prepare the Statement PreparedStatement aStatement = con.prepareStatement(“select firstname, lastname from cfexamples where empid = ?”); aStatement.setInt(1, 2); Sets the first parameter (?) to the value 2 Finds empid=2

Database Access: In Java Execute the query using the Statement object’s method executeQuery() method or the CallableStatement object’s execute() method. ResultSet rs = aStatement.executeQuery(); Accessing the data from the ResultSet rs.getString(1); rs.getString(2);

Displaying ResultSet: Scriptlets One Row if(rs.next()) { out.println(“Hello “ + rs.getString(1) + “ “ + rs.getString(2)); } Many Rows while(rs.next()) { out.println(“Hello “ + rs.getString(1) + “ “ + rs.getString(2)); }

Displaying ResultSet: JSP One Row Hello Many Rows Hello

More topics to learn Java Language, libraries, data types Concepts like classes, methods, packages, public/private/protected/”friendly”, static/final, much more J2EE JDBC, Enterprise Java Beans, JINI, JNDI, JMS, etc. JSP JSP Custom Tags JSP Page Directives Error Handling …

More topics to learn SQL in scripts vs EJB Servlets/JSP Request/response objects, headers, response codes Integrating servlets and JSP’s Battle line among supporters of each Best used in tandem, where each best fits And much more

Learning More Excellent documentation with Jrun Several books Core Servlets and JSP, Marty Hall Professional JSP, Wrox Press Pure JSP, James Goodwill Java Server Pages Application Development, Scott Stirling, Ben Forta, et al And others Thinking in Java, Bruce Eckel eckelobjects.com

Learning More Several CFDJ Articles Java For Cfers, Ben Forta 3 parts, starting November 2000 ColdFusion & Java: A Cold Cup o’ Joe, Guy Rish 9 parts, starting in Jan 2001 Also see Java Developer’s Journal

JSP/Servlet Engine Providers Allaire Jrun 3 person developer edition available free! Can install on same server as CF Server IBM WebSphere BEA WebLogic Apache/TomCat others

Java Editing Tools Jrun Studio CF Studio also supports JSP Kawa Others, from competing JSP engine providers

CF 6.0 AKA NEO CF, as we know it But on top of a Java, rather than C++ platform Basically transparent to CF developers Strength of JAVA, ease of CF Backwards compatibility Scalability built on a leading container (JRUN) May be made available on other Java Server vendor platforms (IBM, BEA, etc.) Still being debated by Allaire, I understand

Leveraging Java in CF Today CFSERVLET CFOBJECT Java Custom Tags TagServlet (from n-ary.com) “wolf in sheep’s clothing” trick How to look like you’re converting your CF code to use JSP when you’re really not

Times Up! Hope you enjoyed the session Send questions to: Charlie Arehart