DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

Java Script Session1 INTRODUCTION.
Chapter 51 Scripting With JSP Elements JavaServer Pages By Xue Bai.
Languages for Dynamic Web Documents
Server-Side vs. Client-Side Scripting Languages
28/1/2001 Seminar in Databases in the Internet Environment Introduction to J ava S erver P ages technology by Naomi Chen.
DT211/3 Internet Application Development
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
JSP Java Server Pages Reference:
Apache Tomcat Server – installation & use Server-side language-- use Java Server Pages Contrast Client-side languages HTML Forms Servers & Server-side.
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,
Website Development with PHP and MySQL Introduction.
Chapter 11 ASP.NET JavaScript, Third Edition. 2 Objectives Learn about client/server architecture Study server-side scripting Create ASP.NET applications.
Three types of scripting elements: 1.Expressions 2.Scriptlets 3.Declarations Scripting elements.
CMPUT 391 – Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems JavaServer Pages (JSP)
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
Julien Thibault / Phil Brewster / Kristina Doing-Harris
Java web development Servlet & Java server pages.
1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Server Side Scripting Norman White. Where do we do processing? Client side – Javascript (embed code in html) – Java applets (send java program to run.
INTRODUCTION TO WEB DATABASE PROGRAMMING
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
Introduction to ASP.NET. Prehistory of ASP.NET Original Internet – text based WWW – static graphical content  HTML (client-side) Need for interactive.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
Chapter 33 CGI Technology for Dynamic Web Documents There are two alternative forms of retrieving web documents. Instead of retrieving static HTML documents,
JSP Java Server Pages Softsmith Infotech.
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Website Design Lecture 1. Outline Introduction to the module Outline of the Assessment Schedule Lecture Static XHTML, client side and server side Why.
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.
Murach’s ASP.NET 4.0/VB, C1© 2006, Mike Murach & Associates, Inc.Slide 1.
JAVA SERVER PAGES CREATING DYNAMIC WEB PAGES USING JAVA James Faeldon CS 119 Enterprise Systems Programming.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Web Pages with Features. Features on Web Pages Interactive Pages –Shows current date, get server’s IP, interactive quizzes Processing Forms –Serach a.
Introduction to JavaServer Pages. 2 JSP and Servlet Limitations of servlet  It’s inaccessible to non-programmers JSP is a complement to servlet  focuses.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
CS 4720 Dynamic Web Applications CS 4720 – Web & Mobile Systems.
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.
CSE 154 LECTURE 5: INTRO TO PHP. URLs and web servers usually when you type a URL in your browser: your computer looks up the.
Introduction to JavaScript CS101 Introduction to Computing.
Overview of Form and Javascript fundamentals. Brief matching exercise 1. This is the software that allows a user to access and view HTML documents 2.
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.
CITA 310 Section 7 Installing and Testing a Programming Environment (Textbook Chapter 7)
Scripting Languages Client Side and Server Side. Examples of client side/server side Examples of client-side side include: JavaScript Jquery (uses a JavaScript.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
 Web pages originally static  Page is delivered exactly as stored on server  Same information displayed for all users, from all contexts  Dynamic.
Core basic Java web server technologies. Tools Eclipse IDE for Java EE Developers (Netbeans also works) nloads/packages/eclipse-
STRUCTURE OF JSP PRESENTED BY: SIDDHARTHA SINGH ( ) SOMYA SHRIVASTAV ( ) SONAM JINDAL ( )
Servers- Apache Tomcat Server Server-side scripts- Java Server Pages.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 2: Introduction to IS2803 Rob Gleasure
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
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 -by Rubeena Memon Deepti Jain Jaya Thakar Jisha Vettuventra.
 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 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.
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.
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,
Web Page Designing With Dreamweaver MX\Session 1\1 of 9 Session 1 Introduction to PHP Hypertext Preprocessor - PHP.
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.
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
Apache Tomcat & Quick Tutorial
JSP Based on
PHP Introduction.
Chapter 27 WWW and HTTP.
PHP.
Lecture 5: Functions and Parameters
Intro to PHP.
Installing Tomcat.
Web Application Development Using PHP
Presentation transcript:

DAT602 Database Application Development Lecture 15 Java Server Pages Part 1

Static webpage VS. Dynamic webpage Classical hypertext navigation, with HTML or XHTML alone, provides "static" content, meaning that the user requests a web page and simply views the page and the information on that page. Database Application Development - Lecture 15

Static webpage VS. Dynamic webpage However, web navigation can also provide an "interactive experience" that is termed "dynamic". Content (text, images, form fields, etc.) on a web page can change, in response to different contexts or conditions. Database Application Development - Lecture 15

There are two ways to create dynamic webpage 1. Using client-side scripting 2. Using server-side scripting Web pages that adhere to the second definition are often created with the help of server- side languages such as PHP, Perl, ASP, ASP.NET, JSP. Database Application Development - Lecture 15

What is JSP? Java Server Pages (JSP) is a server side Java technology that allows software developers to create dynamically generated web pages, with HTML, XML, or other document types, in response to a Web client request to a Java Web Application container (server). Database Application Development - Lecture 15

JSP Server You must have a JSP capable web-server or application server for running your JSP webpages. There are many such servers available: TomCat from Apache WebLogic from BEA Systems WebSpherefrom IBM Database Application Development - Lecture 15

How to install Tomcat in Windows OS? Before installing Tomcat, please ensure you already install the Java successfully in your Windows. Step 1:Download Tomcat. The latest version is , you can download it from following link: 6/v6.0.20/bin/apache-tomcat zip Database Application Development - Lecture 15

How to install Tomcat in Windows OS? Step 2: Unzip this downloaded zip file. You can put it in any place you want. Step 3: Configure environment variable. Add a path “TOMCAT_HOME” which value is the path of Tomcat directory. Step 4: Startup Tomcat server. Run “startup.bat” under../Tomcat/bin. Step 5: Open a web browser, type there should be a webpage if you install Tomcat successfully. Database Application Development - Lecture 15

Your first JSP JSP simply puts Java inside HTML pages. You can take any existing HTML page and change its extension to ".jsp" instead of ".html". What is happening behind the scenes is that your JSP is being turned into a Java file, compiled and loaded. NOTE: you must deploy your jsp file in your jsp server. For tomcat, there is a directory “webapps” for your jsp. Database Application Development - Lecture 15

Adding dynamic content via expressions Change extension from.html to.jsp, that makes JSP useful is the ability to embed Java. Add following code into index.jsp The character sequences enclose Java expressions, which are evaluated at run time. Database Application Development - Lecture 15 Hello! The time is now

Scriptlet JSP also allows you to write blocks of Java code inside the JSP. You do this by placing your Java code between characters. This block of code is known as a "scriptlet". Database Application Development - Lecture 15

Scriptlet Here is a modified version of our JSP from previous section, adding in a scriptlet. Database Application Development - Lecture 15 <% // This is a scriptlet. Notice that the "date" // variable we declare here is available in the // embedded expression later on System.out.println( "Evaluating date now" ); java.util.Date date = new java.util.Date(); %> Hello! The time is

Output in JSP By itself a scriptlet does not generate HTML. If a scriptlet wants to generate HTML, it can use a variable called "out". This variable does not need to be declared. Database Application Development - Lecture 15

Example of using “out” in JSP The "out" variable is of type javax.servlet.jsp.JspWriter.javax.servlet.jsp.JspWriter Database Application Development - Lecture 15 <% // This scriptlet declares and initializes “date” System.out.println( "Evaluating date now" ); java.util.Date date = new java.util.Date(); %> Hello! The time is now <% // This scriptlet generates HTML output out.println( String.valueOf( date )); %>

Variable “request” (javax.servlet.http.HttpServeletRequest) It is a pre-defined variable. A "request" in server-side processing refers to the transaction between a browser and the server. When someone clicks or enters a URL, the browser sends a "request" to the server for that URL, and shows the data returned. Database Application Development - Lecture 15 request Browser Server

Variable “request” The JSP "request" variable is used to obtain information from the request as sent by the browser. Database Application Development - Lecture 15 <% // This scriptlet declares and initializes "date" System.out.println( "Evaluating date now" ); java.util.Date date = new java.util.Date(); %> Hello! The time is now <% out.println( date ); out.println( " Your machine's address is " ); out.println( request.getRemoteHost()); %> Example of getting requester’s IP from “request”

Variable “response” A similar variable is "response". This can be used to affect the response being sent to the browser. For instance, you can call response.sendRedirect( anotherUrl ); to send a response to the browser that it should load a different URL. This response will actualy go all the way to the browser. The browser will then send a different request, to "anotherUrl". Database Application Development - Lecture 15 response Browser Server

Mixing Scriptlets and HTML For more complicated HTML, using the “out” variable all the time loses some of the advantages of JSP programming. It is simpler to mix scriptlets and HTML. In following example, we generate a table containing the numbers from 1 to N. Database Application Development - Lecture 15 Number

Mixing Scriptlets and HTML The important things to notice are how the %> and <% characters appear in the middle of the "for" loop, to let you drop back into HTML and then to come back to the scriptlet. The concepts are simple here -- as you can see, you can drop out of the scriptlets, write normal HTML, and get back into the scriptlet. Database Application Development - Lecture 15

Mixing Scriptlets and HTML Another example of mixing scriptlets and HTML is shown below -- here it is assumed that there is a boolean variable named "hello" available. If you set it to true, you will see one output, if you set it to false, you will see another output. Database Application Development - Lecture 15 Hello, world Goodbye, world

JSP Directives It is possible to use "import" statements in JSPs, but the syntax is a little different from normal Java. Try the following example: Database Application Development - Lecture 15 <% System.out.println( "Evaluating date now" ); Date date = new Date(); %> Hello! The time is now

JSP Directives A JSP "directive" starts with characters. To import more than one item, separate the package names by commas, e.g. Database Application Development - Lecture 15

JSP Directives The include directive is used to physically include the contents of another file. The included file can be HTML or JSP or anything else -- the result is as if the original JSP file actually contained the included text. To see this directive in action, create a new JSP. Database Application Development - Lecture 15 Going to include hello.jsp...

Reference: Database Application Development - Lecture 15