May 13th, Lucek Consulting Basic Java Servlet/JSP Web Development David Lucek Lucek Consulting

Slides:



Advertisements
Similar presentations
Java OSS Web Technologies By Dave Ford Introduction Purpose Describe Javas relationship to the OSS community Describe OSS tools used on recent project.
Advertisements

JSP and web applications
Struts Portlet Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
WEB SERVICES. FIRST AND FOREMOST - LINKS Tomcat AXIS2 -
Developing in CAS. Why? As distributed you edit CAS 3 with Eclipse and build with Maven 2 – Best Practice for Release Engineering – Difficult edit-debug.
Apache Struts Technology
A Blackboard Building Block™ Crash Course for Web Developers
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
Using JavaServer Pages Harry R. Erwin, PhD CIT304/CSE301.
Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.
WEB1P servintro1 Introduction to servlets and JSP Dr Jim Briggs.
28/1/2001 Seminar in Databases in the Internet Environment Introduction to J ava S erver P ages technology by Naomi Chen.
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
DT228/3 Web Development JSP: Directives and Scripting elements.
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.
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.
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.
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.
Apache Jakarta Tomcat Suh, Junho. Road Map Tomcat Overview Tomcat Overview History History What is Tomcat? What is Tomcat? Servlet Container.
Quick Tour of the Web Technologies: The BIG picture LECTURE A bird’s eye view of the different web technologies that we shall explore and study.
Tomcat Celsina Bignoli History of Tomcat Tomcat is the result of the integration of two groups of developers. – JServ, an open source.
Intro to Servlets Lec 26. Web-Based Enterprise Applications in Java Figure shows a simplified view of one application and its layers.
Eclipse is an open source IDE (Integrated Development Environment) for developing applications in Java, C/C++, HTML, Cobol, Perl, etc. The official Eclipse.
Struts 2.0 an Overview ( )
UNIT-V The MVC architecture and Struts Framework.
Java Server Pages B.Ramamurthy. Topics for Discussion 8/20/20152 Inheritance and Polymorphism Develop an example for inheritance and polymorphism JSP.
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.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Apache Tomcat Web Server SNU OOPSLA Lab. October 2005.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 9 JavaServer Pages (JSP) (Based on Møller.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
Applets & Servlets.
SchwartzGBIF Nodes III29 April 2003 DiGIR Portal Installation And Configuration.
CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES LECTURE 5_1 George Koutsogiannakis/ Summer
AN OVERVIEW OF SERVLET TECHNOLOGY SERVER SETUP AND CONFIGURATION WEB APPLICATION STRUCTURE BASIC SERVLET EXAMPLE Java Servlets - Compiled By Nitin Pai.
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
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.
Active Server Pages (ASP), also known as Classic ASP or ASP Classic, was Microsoft's first server-side script engine for dynamically generated web pages.
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
Java Servlets and Java Server Pages Norman White Stern School of Business.
An Introduction to JavaServer™ Pages Prepared by Nicole Swan.
JSP Server Integrated with Oracle8i Project2, CMSC691X Summer02 Ching-li Peng Ying Zhang.
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.
STRUCTURE OF JSP PRESENTED BY: SIDDHARTHA SINGH ( ) SOMYA SHRIVASTAV ( ) SONAM JINDAL ( )
1 G52IWS: Example Web-services Chris Greenhalgh. 2 Contents Software requirements AXIS web service run-time components Getting started with Jetty & AXIS.
Java Servlets and Java Server Pages
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.
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.
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.
Apache Struts Technology A MVC Framework for Java Web Applications.
1 Web Programming with Servlets & JSPs WEB APPLICATIONS – AN OVERVIEW.
Java Server Pages Can web pages be created specially for each user?
APACHE TOMCAT WEB SERVER
Course Outcomes of Advanced Java Programming AJP (17625, C603)
PHP / MySQL Introduction
MSIS 655 Advanced Business Applications Programming
J2EE Application Development
Apache Tomcat Web Server
The Model Layer What is Model?
Introduction to JBoss application server
Java Server Pages (JSP)
ESIS Consulting LLC (C) ESIS Consulting LLC. All rights reserved
Installing Tomcat.
Presentation transcript:

May 13th, Lucek Consulting Basic Java Servlet/JSP Web Development David Lucek Lucek Consulting

May 13th, 2003 Download the Sample Application Download from select the downloads tabwww.lucek.com Includes the full source Unzip to c:\ drive or $HOME/lucek

May 13th, 2003 What is a Servlet? Java Servlets/JSP are part of the Suns J2EE Enterprise Architecture – The web development part Java Servlet – is a simple, consistent mechanism for extending the functionality of a web server – Are precompiled Java programs that are executed on the server side. – Require a Servlet container to run in Latest Servlet Spec is 2.3

May 13th, 2003 What is a Java Server Page (JSP) Java Server Pages (JSP) – A simplified, fast way to create dynamic web content – HTML or XML pages with embedded Java Code or Java Beans – Can be a mix of template data in HTML/XML with some dynamic content – A JSP is a complied to a Java Servlet automatically by the Servlet container, it is then cached Latest JSP Spec is 1.2

May 13th, 2003 Why Use Servlets? Work well in a Heterogeneous Environments – OS and platform neutral – Work with all major web servers (IIS, Apache,etc..) Well defined Web Architecture framework – Standard built in services such as: Standard Approach to Authentication using declarative security vice programmatic security Database connection pooling Complete support for sessions via cookies and/or URL re-writing – Has automatic fallback to URL re-writing

May 13th, 2003 Why Use Servlets Cont? – Robust Object-Orientated API in Java language Ever try to maintain a large ASP, Perl, or PHP site Clean separation of Controller/Logic from Presentation Efficient, scales very well There are good free Servlet/JSP containers and connectors – That run under both UNIX and win32

May 13th, 2003 J2EE Web Application Components Java Servlets – Extend off of HttpServlet JSP pages, normally for Presentation Java Beans – Normally used as value objects, pass to data to JSPs Tag Libraries – XML based JSP elements Web Deployment Descriptor – /web-inf/web.xml

May 13th, 2003 Web Deployment Descriptor /web-inf/web.xml – Part of the standard – Defines servlets used in the web application – Maps servlets to URLs – A servlet can map to many URLs Defines resources available to the web app Defines security constraints Defines other stuff like – Welcome file list – Session timeout – Error page mapping

May 13th, 2003 J2EE Web Directory Structure 1 Top Directory is normally the context Path – /tomcat/webapps/servletdemo – Normally, the URL would be – Contains JSP and other static content plus the web-inf directory /web-inf directory – This is a protected directory, can not point browser to any file in this directory – /classes – unpacked web application classes, auto-magically added to CLASS_PATH – /lib – web application JAR files – /taglib – tag library descriptor files

May 13th, 2003 J2EE Web Directory Structure 2 /web-inf/web.xml /web-inf/* – Would normally put any static or JSP files here – Protects them from Direct Invocation – Always best to call a JSP through a servlet first

May 13th, 2003 JSP Constructs 1 Used in JSP pages, pages that end *.jsp Comment Declaration Expression – Outputs to the Response stream – Like a printf to the browser – Do NOT use semi-colon to terminate the line Scriplets - contains Java Code –

May 13th, 2003 JSP Constructs 2 The value is: Value is empty Implicit objects always available in the JSP Page – request – Browsers Request Object Use to get HTTP headers, length etc.. – response - HttpResponse Object

May 13th, 2003 JSP Constructs 3 – session – internal HttpSession Object – pageContext – application – out, same as – config – servlet configuration – page – exception JSP Directives – Are messages or instructions to the JSP container

May 13th, 2003 JSP Constructs 4 – Do not produce any output – page directive Commonly used for importing class paths – include directive Good for including static content – taglib – lists the tag library descriptor location Required when using tab libraries

May 13th, 2003 Java Beans as Used in Web Apps Normally used for all data transfers and business components Similar to how Java Beans are used in Swing and AWT – But do not need the full implementation Must have no constructor or no-arg constructor Must have setter and getter methods for each property value JSP constructs/tags use Java Beans

May 13th, 2003 JSP Actions JSP actions are special tags that affect the output stream and are normally used with Java beans – Most commonly used:,, The code below will display the lastName property of the student bean on the output stream

May 13th, 2003 Servlet Container/Engine Servlets/JSP require a Container Apache Tomcat is the reference implementation of the Servlet/JSP Specs It is open source, small, install quickly,and is FREE Latest Version is Web Site: jakarta.apache.org/tomcat It include a simple HTTP 1.1 server, good enough for development and small intranets.

May 13th, 2003 Tomcat Install Requires a JDK, get and install into c:\jdk or $HOME/jdk Add JAVA_HOME to your environment and the bin directory to your PATH Good practice to unpack into c:\tomcat or $HOME/tomcat Add CATALINA_HOME to your environment and the bin directory to your PATH

May 13th, 2003 Tomcat Directory Structure Everything is relative to $CATALINA_HOME /bin – Startup/shutdown scripts /conf – Server.xml – main configuration file /common – common class and jar files used by Tomcat and web applications – Put JDBC drivers here /server – class and jar files used by Tomcat internally /shared – class and jar files for all web applications /webapps – This is where you put your web application in a sub-directory or external context file.

May 13th, 2003 Starting Tomcat /bin/startup.bat or startup.sh Point Browers to should see default pagehttp://localhost:8080 All the Docs are there on the default page! Check out the examples pages, good tutorials

May 13th, 2003 Other Development Tools 1 Ant Build Tool – Standard Java Build tool – Basic on UNIX make, but much better – Site: – Install in c:\ant or $HOME/ant Java IDE – Try NetBeans, it is nice – Tomcat is built in, but is an older version – Includes full Servlet and JSP debugging – Site:

May 13th, 2003 Other Development Tools 2 Junit – Standard Automated Unit Testing Tool – Site: Jedit – Slick Programmers Editor – Written in Java – Site: jedit.org

May 13th, 2003 Simple Servlet Application 1 See servletdemo code Mount the servletdemo, servletdemo/java/src, and servletdemo/web in NetBeans Explorer Tab For a Hello World Servlet look at: – Java/src/com/lucek/action/HelloWorld.java To build and run – $ cd servletdemo – Setup the proper build variables in the build.properties file – $ ant all – $ ant deploy – Point your browsers at

May 13th, 2003 Simple Servlet Application 2 Look at the web.xml file and how the same servlet can be mapped to many URLs Look at SimpleBean.java which should how to pass a Java Bean to a JSP page Look at the different ways a beans value can be obtained in the EditStudent.jsp

May 13th, 2003 Best Practices/Patterns Always Separate out the logic from the presentation – Use servlets for the logic/controller and JSPs for presentation – Ideally should never have Java Code in the JSP page Have a clean separation between your data access and controller layers (DAO) Always use DTO or value object Use a Model-View-Controller Architecture – Do not write it, use Struts – Site: jakarta.apache.org/struts/ Use Unit tests – Junit Automation via Ant build tasks

May 13th, 2003 What we have not talked about All the specific Servlet APIs Tag libraries Sessions, cookies JDBC service support from the container Container based authentication Lots of other stuff

May 13th, 2003 Next Presentation? Create a data driven web site using MySql and Servlets/JSP Setup Authentication Realm with declarative security Setup JDBC connection pooling Struts?