Java Servlets and Java Server Pages Norman White Stern School of Business.

Slides:



Advertisements
Similar presentations
Lecture plan Information retrieval (from week 11)
Advertisements

Java Server Pages (JSP)
JSP1 Java Server Pages (JSP) Introducing JavaServer Pages TM (JSP TM ) JSP scripting elements.
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
Java Servlet & JSP © copyright 2005 SNU OOPSLA Lab.
J.Sant Servlets Joseph Sant Sheridan Institute of Technology.
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.
WEB1P servintro1 Introduction to servlets and JSP Dr Jim Briggs.
An introduction to Java Servlet Programming
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
JSP Java Server Pages Reference:
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 Team 8. Overview What is a Java Server? History Architecture Advantages Disadvantages Current Technologies Conclusion.
Introduction to Servlet & JSP
Comp2513 Java Servlet Basics Daniel L. Silver, Ph.D.
1 Java Server Pages Can web pages be created specially for each user? What part does Java play?
Java Server and Servlet CS616 Team 9 Kim Doyle, Susan Kroha, Arunima Palchowdhury, Wei Xu.
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.
Servlets. Our Project 3-tier application Develop our own multi-threaded server Socket level communication.
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.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
Server-side Technologies
Introduction Servlets and JSP Celsina Bignoli
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.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
Applets & Servlets.
Introduction to JAVA Instructor : Simon Hui & Louis Wong Industrial Centre The Hong Kong Polytechnic University Sep, 2002.
Java Omar Rana University of South Asia. Course Overview JAVA  C/C++ and JAVA Comparison  OOP in JAVA  Exception Handling  Streams  Graphics User.
Servlets. - Java technology for Common Gateway Interface (CGI) programming. - It is a Java class that dynamically extends the function of a web server.
Chapter 17 - Deploying Java Applications on the Web1 Chapter 17 Deploying Java Applications on the Web.
JSP Java Server Pages Softsmith Infotech.
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.
SKT-SSU IT Training Center Servlet and JSP. Chapter Three: Servlet Basics.
111 Java Servlets Dynamic Web Pages (Program Files) Servlets versus Java Server Pages Implementing Servlets Example: F15 Warranty Registration Tomcat Configuration.
J2EE Structure & Definitions Catie Welsh CSE 432
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.
Java Servlets & Java Server Pages Lecture July 2013.
1 CS122B: Projects in Databases and Web Applications Spring 2015 Notes 03: Web-App Architectures Professor Chen Li Department of Computer Science CS122B.
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
1 Java Servlets l Servlets : programs that run within the context of a server, analogous to applets that run within the context of a browser. l Used to.
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.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
Java Servlets and Java Server Pages
How CGI and Java Servlets are Run By David Stein 14 November 2006.
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.
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.
Speaker Name Speaker Title Speaker Title Oracle Corporation Olivier Le Diouris Principal Product Manager Oracle Corporation Building Servlet and JSP Applications.
Distributed Web Systems Java Servlets Lecturer Department University.
Java Server Pages Can web pages be created specially for each user?
CS122B: Projects in Databases and Web Applications Spring 2017
Introduction to Servlets
CS122B: Projects in Databases and Web Applications Winter 2017
Introduction Servlets and JSP
Server Side Programming
Servlet Fudamentals.
Java Servlets By: Tejashri Udavant..
Introduction to Java Servlets on Jakarta Tomcat
Servlets and Java Server Pages
CS122B: Projects in Databases and Web Applications Winter 2018
Introduction to Servlets
CS122B: Projects in Databases and Web Applications Spring 2018
Java Chapter 7 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Java Servlets and Java Server Pages Norman White Stern School of Business

Agenda Servlets JSPs J2EE Architecture EJBs

But first, Applets Java Applet –Self contained Java program that is downloaded and run under browser –Java Object oriented language similar to C++ –Supports classes, inheritance etc. Compiled to “Java Virtual Machine” (JVM) object code JVM can be implemented I many environments Java originally designed as a machine control language Java Applets run under Browser with security features that restrict what they can do (like read hard drive)

What are Java Servlets Java Servlets are essentially server side applets (I.e. run on a server as opposed to under the browser). Since they run on the server, their output is sent directly to the browser, hence they generate the web page output dynamically

Servlets Servlets are Java classes managed by a servlet container hosted by a Web server. Servlets are mapped to URLs by the servlet container. HTTP requests to a servlet's URL are passed to an instance of the servlet, which generates response content that is returned to the client as the HTTP response. Servlets receive input variables from the HTTP request, can maintain state across invocations, and have control of the content type the server returns. Servlets provide a portable, safe, efficient, and highly general mechanism for extending a Web server.

Java Server Pages Servlets are powerful, but they require programming. JSP pages provide a "structural" way to create dynamic textual content, as an alternative to the "programmatic" method offered by servlets. A JSP page is an HTML page with special markup that produces dynamic content. –I.e. embedded scripting statements which are executed on the server, not the client.

JSPs Although a JSP page's source code looks like HTML, it's actually implemented by a servlet. When a client accesses a JSP page, the Web server translates the JSP page into a Java language servlet, compiles and loads the servlet, and then passes the request to the servlet. (If the servlet is already loaded, the server skips the translation, compilation, and loading.) So, a JSP page is simply an easy way to specify a servlet that produces mostly structured data.

JSP Custom Tags But even JSP demands that the page developer knows some Java JSP developers can use JSP to define new XML (eXtensible Markup Language) tags for non-technical users to use in JSP pages. The JSP custom tags are expanded into JSP Scriptlets and then executed.

But Wait, doesn’t this involve a lot of overhead Answer, yes but… Trick is, JSP pages are only turned into Servlets when they change. Non-technical developers can make changes at the JSP Custom Tag level, and they automatically get translated into JSP scriptlets, and then the whole page is translated into a Servlet.

I Am Completely Confused!! This is way too complex… But that is why you get the big bucks…

Advantages over CGI Efficient –Less process startup overhead with Servlets, they stay in memory for reuse. Convenient –Built-in support for HTML forms, cookies etc. Written in Java Powerful –Can talk directly to web server, share data, make Data base connections, save information, track sessions etc. Portable- –Write once, run anywhere. Great for a mixed environment Inexpensive –Inexpensive to add servlet support

Examples import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class SomeServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Use "request" to read incoming HTTP headers (e.g. cookies) // and HTML form data (e.g. data the user entered and submitted) // Use "response" to specify the HTTP response line and headers // (e.g. specifying the content type, setting cookies). PrintWriter out = response.getWriter(); // Use "out" to send content to browser }

Hello World package hall; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloWorld extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println("Hello World"); }

Hello WWW package hall; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloWWW extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " + "Transitional//EN\">\n" + " \n" + " Hello WWW \n" + " \n" + " Hello WWW \n" + " "); }

Package-Puts out Title package hall; public class ServletUtilities { public static final String DOCTYPE = " "; public static String headWithTitle(String title) { return(DOCTYPE + "\n" + " \n" + " " + title + " \n"); } // Other utilities will be shown later... }

Using the Package package hall; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloWWW2 extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println(ServletUtilities.headWithTitle("Hello WWW") + " \n" + " Hello WWW \n" + " "); }

OK, I think I get it Java servlets allow me to write CGI like programs in Java, but without the overhead of CGI, and with more power. But what good is this? Is it that much better than ASP, PhP etc.?

Answer Servlets can generate any output type, so they can stream multimedia, generate images, etc. Especially nice if they are sending something to a Java applet running on the browser.

Servlets are not just Java Applets Servlets are part of a complete development environment that can run anywhere. Java Version 2 Enterprise Edition (J2EE) includes Servlets (and Java Server Pages) as part of the environment They are quickly becoming part of a standard cross platform development environment supported by many Manufacturers

What is new here? Write once, run anywhere development Ability to easily redistribute applications across multiple servers of any type High level standards support of many new technologies Component based development environment In short, an architecture for enterprise application development

J2EE Architecture elements Distributed Communications –Network, web, RMI, CORBA, DCOM Enterprise Data Enabling –JDBC Common Services –Naming Services Directory and Trading services, Activation Services, messaging Services, Transaction Services Enterprise Systems Assurance –Built-in Security supporting Java, CORBA Enterprise Web Enabling –XML, Java Servlets, Java Server Pages Enterprise Applications Enabling –Enterprise Application Platforms, Application servers and Enterprise Java Beans (EJBs).Modeling with EJBs

EJBs – Enterprise Java Beans These are business logic components which depend on services provided by the EJB container. Applications are built by creating new types of session beans and entity beans for handling transactions. Since they extend the session or entity Bean class, Beans inherit services including security, transaction management and data base integration.

EJBs – Enterprise Java Beans

Application Tiers & Responsibilities

Management Takeaway Java Servlets and Java Server Pages are part of a much larger environment that can provide an integrated, cross- platform, scalable, secure, robust set of “industry standard” systems.

But what about more mundane uses Java Server Pages (JSP) These are HTML files with embedded Java code (Scriptlets) The first time the file is referenced, the complete JSP file is turned into a Java Servlet and compiled. The resulting servlet can be developed much faster and more reliably without sacrificing performance.

Advantages Easy to maintain, user doesn’t really need to know much if any Java Runs faster, since everything is compiled Opens WEB development up to full Java toolkit including Enterprise Java Beans

Conclusion Java Servlets and Java Beans are being used for most high-end web sites Extends web model to include tightly integrated Java Applets and Java servlets Basis of most new peer to peer applications Learn Java!!