Net-centric Computing

Slides:



Advertisements
Similar presentations
Java Servlets Java Server Pages (JSP)
Advertisements

 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
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.
Servlets Stoney Jackson
CSE 190: Internet E-Commerce Lecture 7. HTML Templates Designed to separate server side logic from HTML presentation Key features –Escapes from HTML into.
An introduction to Java Servlet Programming
Servlets. A form The HTML source Chapter 1 Please enter your name and password then press start Name: Password: In Netbeans you can graphically create.
Introduction to Servlet & JSP
Comp2513 Java Servlet Basics Daniel L. Silver, Ph.D.
Java Server and Servlet CS616 Team 9 Kim Doyle, Susan Kroha, Arunima Palchowdhury, Wei Xu.
Server Side Programming Web Information Systems 2012.
Servlets. Our Project 3-tier application Develop our own multi-threaded server Socket level communication.
SE-2840 Dr. Mark L. Hornick1 Java Servlet-based web apps Servlet Architecture.
Java Servlets and JSP.
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.
Servlets. - Java technology for Common Gateway Interface (CGI) programming. - It is a Java class that dynamically extends the function of a web server.
Chapter 5 Java Servlets. Objectives Explain the nature of a servlet and its operation Use the appropriate servlet methods in a web application Code the.
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.
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.
Servlet Lifecycle Lec 28. Servlet Life Cycle  Initialize  Service  Destroy Time.
Chapter 3 Servlet Basics. 1.Recall the Servlet Role 2.Basic Servlet Structure 3.A simple servlet that generates plain text 4.A servlet that generates.
Java Servlets Lec 27. Creating a Simple Web Application in Tomcat.
Chapter 2 Web app architecture. High-level web app architecture  When a client request coming in and needs servlet to serve dynamic web content, what.
20-Nov-15introServlets.ppt Intro to servlets. 20-Nov-15introServlets.ppt typical web page – source Hello Hello.
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
Java Servlet API CGI / HTTP Concepts Java Servlet API.
Introduction to Server-Side Web Development Introduction to Server-Side Web Development Session II: Introduction to Server-Side Web Development with Servlets.
Java Servlets and Java Server Pages Norman White Stern School of Business.
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.
Java Servlets Java Server Pages (JSP)
Configuration Web Server Tomcat - Install JDK Install Tom cat Configure Tom cat for running Servlet C:\Program Files\Apache Software Foundation\Tomcat.
Java Servlets and Java Server Pages
Introduction To HTML Dr. Magdi AMER. HTML elements.
How CGI and Java Servlets are Run By David Stein 14 November 2006.
Distributed Web Systems Java Servlets Lecturer Department University.
Introduction to Servlets
Building Web Apps with Servlets
Server Side Programming
Servlet Fudamentals.
Java Servlets By: Tejashri Udavant..
JDBC & Servlet CSE 4504/6504 Lab.
Course Outcomes of Advanced Java Programming AJP (17625, C603)
Servlets Hits Counter 20-Jul-18.
Introduction to Java Servlets on Jakarta Tomcat
HTTP Servlet Overview Servlets are modules that extend request/response-oriented servers, such as Java-enabled web servers. For example, a servlet might.
Servlet.
Chapter 26 Servlets.
Jagdish Gangolly State University of New York at Albany
Servlets and Java Server Pages
Servlets and JSP 20-Nov-18 servletsJSP.ppt.
Servlets CEN /28/2018 Copyright 2001 Ege Consulting, Inc.
Web Search Interfaces.
Java Servlets and JSP.
Web Search Interfaces by Ray Mooney
CS3220 Web and Internet Programming Introduction to Java Servlets
Servlets.
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
Java Servlets Servlet Overview Servlets and HTML Forms Servlet Basics
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
Directories and DDs 25-Apr-19.
Introduction to Servlet
Basic servlet structure
Directories and DDs 21-Jul-19.
Directories and DDs 14-Sep-19.
Presentation transcript:

Net-centric Computing Java Servlets

Lecture Outline Why Servlet What is Servlet History How Servlet Works What the container (e.g. Tomcat) does Setting up to run servlet Simple Examples

Why Servlet The need for servlet Support creation of Dynamic web pages Reduce the overhead on the server and network To take care of processing data on the Web server

What is Servlet Servlet: Java programs that can be deployed on a Java enabled Web server A Java class that can respond to HTTP requests Runs in a special web server, the servlet container

History CGI CGI Servlet JSP Template (ASP, PHP) (java, C++) (in C) complexity Speed, Security Servlet JSP

How it works for Java Servlets Web server app is commonly Apache Web container app is Tomcat Servlets are run by Tomcat SE-2840 Dr. Mark L. Hornick

What the container does Communication Creates server-side sockets Listens for client connections Determines client HTTP request type and “decodes” HTTP headers Servlet Lifecycle management Figures out which Servlet should be used to process a specific request Handles Servlet class loading Handles Servlet instantiation/construction Handles Servlet initialization Servlet execution support Launches/manages threads that service each incoming request Handles Servlet service() method invocation Creates and passes Request and Response objects to the Servlet Supports Security Supports JSP

Servlets Life Cycle CS-4220 Dr. Mark L. Hornick Web Container (Tomcat) This is where the servlet spends most of its life Web Container (Tomcat) Your servlet class CS-4220 Dr. Mark L. Hornick

Steps to run servlet on xampp Set environment variables Enter the paths ,;C:\xampp\tomcat\lib\servlet-api.jar and lib folder of Java installation (e.g. C:\Java\jdk1.8.0_31\lib) in the CLASSPATH system variable Enter the path for bin folder of Java installation (e.g. C:\Java\jdk1.8.0_31\bin) in the PATH system variable Classes must be in WEB-INF/classes folder (inside c:\tomcat\webapps\<?>)

Steps to run servlet on xampp Configure the WEB-INF/web.xml file as follows (YourFileName.class): <servlet>      <servlet-name>YourFileName</servlet-name>      <servlet-class>YourFileName</servlet-class> </servlet> <servlet-mapping>      <servlet-name>YourFileName</servlet-name>      <url-pattern>/YourFileName</url-pattern> </servlet-mapping>

Servlet Example 1 http://localhost:8080/servlet/MyServlet

HelloWorld import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloWorld extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<body>"); out.println("<head>"); out.println("<title>Hello CS764!</title>"); out.println("</head>"); out.println("<h1>Hello CS764!</h1>"); out.println("</body>"); out.println("</html>"); out.close(); }

<html><head></head> <body> <a href=" <html><head></head> <body> <a href="../servlet/HelloWorld"> <h1>Execute HelloWorld Servlet</h1> </a> </body> </html> <html> <head> <title>Hello CS764!</title></head> <body> <h1>Hello CS764!</h1> </body> </html>

Example 3: Get Stock Price Ass2.html <html><head></head> <body> <form action="../servlet/Ass2Servlet" method=POST> <h2>Stock Symbol name: <input type=text name="stockSymbol"></h2><br> <input type="submit" value = "get price"> </form> </body></html> Client Side

Ass2Servlet public class Ass2Servlet extends HttpServlet { import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; public class Ass2Servlet extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); String stockSymb = request.getParameter("stockSymbol"); StockGrabber sg = new StockGrabber(); sg.setStockSymbol(stockSymb); // Set the stock symbol as “input” String stockPrice = sg.getPrice();// Get the price of stock System.out.println("After StockGrabber.getPrice --"+stockPrice);// Debug out.println("<html><head></head><body><br><br>"); out.println(stockSymb + " -- " + stockPrice); out.println("<hr>"); out.println("<form action=\"../servlet/Ass2Servlet\" method=POST>"); out.println("<h3>Stock Symbol name: <input type=text name=\"stockSymbol\"></h3>"); out.println("<input type=submit value=\"get price\">"); out.println("</form>"); out.println("</body></html>"); }

Servlets vs. Java Applications Servlets do not have a main() The main() is in the server Entry point to servlet code is via call to a method (doGet() in the example) Servlet interaction with end user is indirect via request/response object APIs Actual HTTP request/response processing is handled by the server Primary servlet output is typically HTML