Tutorial: Server-Side Web Applications with Java, JSP and Tomcat Eran Toch December 2004 Methodologies in Information Systems Development.

Slides:



Advertisements
Similar presentations
Apache Struts Technology
Advertisements

JSP1 Java Server Pages (JSP) Introducing JavaServer Pages TM (JSP TM ) JSP scripting elements.
Using JavaServer Pages Harry R. Erwin, PhD CIT304/CSE301.
Web MVC-2: Apache Struts Rimon Mikhaiel
Web applications using JavaServer Faces (JSF) A brief introduction 1JavaServer Faces (JSF)
JSP: JavaServer Pages Juan Cruz Kevin Hessels Ian Moon.
Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.
Tutorial: Writing and Calling Web Services using Java Eran Toch November 2004 Methodologies in the Development of Information Systems.
DT228/3 Web Development JSP: Directives and Scripting elements.
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,
1 Java Server Pages Can web pages be created specially for each user? What part does Java play?
Web programming for project students Dr Jim Briggs.
Apache Struts Technology A MVC Framework for Java Web Applications.
Web Applications Basics. Introduction to Web Web features Clent/Server HTTP HyperText Markup Language URL addresses Web server - a computer program that.
ECE356 – Database Systems Lab 1 – Building a Web Project with NetBeans Tiuley Alguindigue Lab Instructor – University of Waterloo, E & CE Dept. Fall 2013.
CS 160: Software Engineering August 27 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Java web development Servlet & Java server pages.
Java Servlets and JSP.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
Java Enterprise Edition Java Web Development Structure of a web project Introduction to Web Applications The first project Introduction to Java Web Development.
Eclipse is an open source IDE (Integrated Development Environment) for developing applications in Java, C/C++, HTML, Cobol, Perl, etc. The official Eclipse.
SEEM4570: XAMPP, Eclipse, Summary of Html Kangfei Zhao Room 711,ERB
Struts 2.0 an Overview ( )
UNIT-V The MVC architecture and Struts Framework.
Java Server Pages (JSP) Presented by: Ananth Prasad & Alex Ivanov May 10, 2001.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
Apache Tomcat Web Server SNU OOPSLA Lab. October 2005.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
CSCI 6962: Server-side Design and Programming Course Introduction and Overview.
Servlets Environment Setup. Agenda:  Setting up Java Development Kit  Setting up Web Server: Tomcat  Setting up CLASSPATH.
Introduction to Java Server Pages (JSPs) Robert Thornton.
Introduction to JavaServer Pages (JSP) Slides from Dr. Mark Llewellyn.
Java Server Pages Lecture July Java Server Pages Java Server Pages (JSPs) provide a way to separate the generation of dynamic content (java)
|Tecnologie Web L-A Anno Accademico Laboratorio di Tecnologie Web Introduzione ad Eclipse e Tomcat
 Embeds Java code  In HTML tags  When used well  Simple way to generate dynamic web-pages  When misused (complex embedded Java)  Terribly messy.
Chapter 8 Script-free pages. Problem with scripting in JSP When you use scripting (declaration, scriplet, expressions) in your JSP, you actually put Java.
® IBM Software Group © 2007 IBM Corporation J2EE Web Component Introduction
Mark Dixon 1 12 – Java Beans. Mark Dixon 2 Session Aims & Objectives Aims –To cover the use of Java Beans Objectives, by end of this week’s sessions,
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.
Lecturer: Prof. Piero Fraternali, Teaching Assistant: Alessandro Bozzon, Advanced Web Technologies: Struts–
JAVA SERVER PAGES CREATING DYNAMIC WEB PAGES USING JAVA James Faeldon CS 119 Enterprise Systems Programming.
Fall CIS 764 Database Systems Design L8. Web ….
Webcommerce Computer Networks Webcommerce by Linnea Reppa Douglas Martindale Lev Shalevich.
Topic Java EE installation (Eclipse, glassfish, etc.) Eclipse configuration for EE Creating a Java Web Dynamic Project Creating your first servlet.
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.
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
Liferay Installation Prepared by: Do Xuan Hai 8 August 2011.
Chính phủ điện tử TS. Phạm Văn Tính Khoa CNTT, ĐH Nông Lâm TP.HCM
CSC 2720 Building Web Applications JavaServer Pages (JSP) JSP Directives and Action Elements.
An Introduction to JavaServer™ Pages Prepared by Nicole Swan.
OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.
An Introduction to JavaServer™ Pages Prepared by Nicole Swan.
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
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 ( )
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
NJIT 1 Apache Tomcat (Version 6.0) THETOPPERSWAY.COM.
Chapter 6 Chapter 6 Server Side Programming (JSP) Part 1 1 (IS 203) WebProgramming (IS 203) Web Programming.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
JAVA, JEE Training Introduction to Web Harinath Mallepally
Apache Struts Technology A MVC Framework for Java Web Applications.
1 Web Programming with Servlets & JSPs WEB APPLICATIONS – AN OVERVIEW.
Unit 6-Chapter 2 Struts.
MSIS 655 Advanced Business Applications Programming
Java Server Pages (JSP)
Presentation transcript:

Tutorial: Server-Side Web Applications with Java, JSP and Tomcat Eran Toch December 2004 Methodologies in Information Systems Development

2 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Agenda Introduction and architecture Installing Tomcat Building a Web Application (through Eclipse) The Phones Web Application –Writing JavaBeans –Writing JSPs Includes, session and application Model 2 Architecture

3 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Web Application vs. Web Site Web SiteWeb Application

4 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development The Difference – cont’d Web sites are –Static –File based –May include client’s JavaScript code Web Applications are –Dynamic (output depend on input) –Database based –Multi-layered –Session dependent (most of the times) –Personalized (some of the times)

5 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development JSP Java Web Application Architecture Application Server Browser Servlet Java Classes / EJB HTTP / HTML DB / ERP / Legacy

6 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Agenda Introduction and architecture Installing Tomcat Building a Web Application (through Eclipse) The Phones Web Application –Writing JavaBeans –Writing JSPs Includes, session and application Model 2 Architecture

7 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Tomcat Installation Go to: Download the latest version (currently 5.5.4) by going to: Downloads -> Binaries -> Tomcat –For Windows, download the exe version – with a Windows setup. The direct link: 5/v5.5.4/bin/jakarta-tomcat exe 5/v5.5.4/bin/jakarta-tomcat exe –For Linux, read the setup manual: doc/setup.html

8 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Tomcat and Java 5 Please note that Tomcat v requires J2SE 1.5 (also known as J2SE 5) or above. If you want to use J2SE 1.4, download Tomcat 5.0.+

9 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Tomcat Installation – cont’d If you want Tomcat to startup every time the computer is rebooted, check the “service” option. If you wish to use Tomcat for only for development, it’s best to leave the service option unchecked.

10 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Tomcat Installation - Port You can configure the port that Tomcat will be using. If you want it to be available publicly (behind firewalls etc), change the default port to 80. Otherwise, leave it as it is (880). You can always change it later, in the [TOMCAT_HOME]/conf/serv er.xml configuration file.

11 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Running Tomcat Start Tomcat by running Tomcat monitor (Start Menu -> Apache Tomcat -> Monitor Tomcat), and click on Start. –Point your browser to: If Tomcat works, you should see something like this –If not, check out the logs (C:\[TOMCAT_HOME]\logs\s tdout) and see what went wrong.

12 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Managing Tomcat Go to the management console by clicking on the “management” link in the Tomcat root homepage, or directly by going to: The default username is “admin”, and the default password is ”” You can change it by changing the [TOMCAT_HOME]\conf\tomcat-users.xml.

13 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Managing Tomcat Console Web Application management Number of current sessions Start, stop, restart and un-deploy applications

14 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Agenda Introduction and architecture Installing Tomcat Building a Web Application (through Eclipse) The Phones Web Application –Writing JavaBeans –Writing JSPs Includes, session and application Model 2 Architecture

15 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Building A Web Application Build the following folder structure under [TOMCAT-HOME]\webapps Tomcat-home confcommonwebapps... phones WEB-INF lib classes jsp This is the hard way… There are better

16 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Creating JSP Project in Eclipse 1.Open a project for the JSP pages 2.Choose the type “Simple project”

17 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Creating JSP Project – cont’d Choose the path to the jsp folder Click “Finish”

18 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Creating Java Classes Project Create a new project Choose “Java Project”

19 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Creating Java Project – cont’d Choose the path to the WEB- INF/classes folder

20 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Creating Java Project – cont’d Make sure the output build path is in the WEB-INF classes folder Necessary libraries could be added now

21 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Better ways Download MyEclipse IDE extension from: Download Lomboz plugin for Eclipse at: Both of these plugins will give you: –Easier deployment of projects –JSP debugging –JSP error detection (important!)

22 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Agenda Introduction and architecture Installing Tomcat Building a Web Application (through Eclipse) The Phones Web Application –Writing JavaBeans –Writing JSPs Includes, session and application Model 2 Architecture

23 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Our “Phones” Application Simple application that displays phone records from the database (stupid, shameless) Architecture: select_entry.jspdisplay_phone.jsp PhoneEntry.java DBConnector.java Database

24 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System DevelopmentPhoneEntry.java package edu.technion.methodologies.phones; public class PhoneEntry { private int id = 0; private String name; private String phone; private String ; public void load(int id){ DBConnector.loadPhone(id, this); } public void save(){ if (id == 0){ id = DBConnector.insertPhone(this); } else{ DBConnector.updatePhone(id, this); } //getters and setters… }

25 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development DBConnector.java See the advanced Java tutorial…

26 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Writing Scriplets in JSP Write HTML as normal Dynamic parts between Eg Hello! The time is now

27 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development JSP Scripting Elements Expressions evaluated and inserted into the output Scriptlets inserted into the servlet's service method Declarations inserted into the body of the servlet class, outside of any existing methods

28 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development JSP Directives There are two main types of directive: –page lets you do things like import classes, customize the servlet superclass etc –Include lets you insert a file into the servlet class at the time the JSP file is translated into a servlet.

29 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development select_entry.jsp Phones Application ID: HTML Header HTML form Nested HTML table structure HTML text input

30 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development select_entry.jsp – the HTML output

31 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development display_phone.jsp Phone Entry <% String idParam = request.getParameter("id"); int id = 0; if (idParam != null){ id = Integer.parseInt(idParam); } PhoneEntry phoneEntry = new PhoneEntry(); phoneEntry.load(id); %> Handling the request Creating the JavaBean Importing libraries

32 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development display_phone.jsp – cont’d Name: Phone:

33 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development display_phone.jsp – the HTML Output

34 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Agenda Introduction and architecture Installing Tomcat Building a Web Application (through Eclipse) The Phones Web Application –Writing JavaBeans –Writing JSPs Includes, session and application Model 2 Architecture

35 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development JSP Include Inserting elements into the JSP page in complication time home Included JSP file

36 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development JSP Include – cont’d … <% … We add the include declarative into display_phone.jsp And we get:

37 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Session and Application Objects A session is an object associated with a visitor. Data can be put in the session and retrieved from it Sessions are timed-out – the default is ~25 minutes The application object is accessed similarly, but is unique and global for the web application //Setting an object within the session session.setAttribute("last_searched_id", new Integer(id)); //Getting an object from the session Integer lastID = (Integer)session.getAttribute("last_searched_id"); out.println(lastID);

38 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Advanced Issues Servlets – have many advantages over JSP –Inheritance –Class structure Tag libraries Enterprise Java Beans J2EE Frameworks (WebLogic, Web Sphere, JBoss)

39 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Agenda Introduction and architecture Installing Tomcat Building a Web Application (through Eclipse) The Phones Web Application –Writing JavaBeans –Writing JSPs Includes, session and application Model 2 Architecture

40 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Model 2 Architecture recommended approach for designing medium- and large-sized Web applications An implementation of the Model-View- Controller (MVC) pattern Applications have 3 layers –Model: containing all data and operations »JSP classes or beans –View: creating various presentations »JSP – focus on static data –Controller: receiving requests, updating the model, and delegating to views »servlet

41 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Model 2 Architecture – cont’d.jsp Form request forward Database classes servlet VIEW CONTROLLER MODEL

42 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development Struts Struts is an open source framework created within the Jakarta project by the Apache Software Foundation Supports Model-View-Controller (MVC) design pattern

43 Server-Side Web Applications with Java, JSP and Tomcat – Eran Toch Methodologies in Information System Development References Core Servlets and JavaServer Pages, Vol. 1: Core Technologies, Second Edition, by Marty Hall, Larry Brown Sun’s JSP Tutorial: fcs/doc/JSPIntro.html fcs/doc/JSPIntro.html JavaBeans Tutorial: fcs/doc/JSPBeans.html fcs/doc/JSPBeans.html A set of advanced (and untidy) tutorials: