In Class Assg 4 - Solution

Slides:



Advertisements
Similar presentations
Apache Tomcat as a container for Servlets and JSP
Advertisements

 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
COMP 321 Week 8. Overview MVC Example Servlet Lifecycle Servlet Mechanics MVC Lab 5-2 Solution Lab 8-1 Introduction.
1 CS6320 – Servlet Request Dispatcher L. Grewe 2 What is the purpose Forward a request from one servlet to another (or jsp). Forward a request from one.
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.
Servlets and JDBC. Servlets A form The HTML source Chapter 1 Please enter your name and password then press start Name: Password:
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.
June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 1 Lecture 10 Object Oriented Programming in Java Advanced Topics Servlets.
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.
1 Web Applications – The Basics. 2 Unzipped Tomcat Folder.
Servlets. A form The HTML source Chapter 1 Please enter your name and password then press start Name: Password:
Servlets. Our Project 3-tier application Develop our own multi-threaded server Socket level communication.
A Servlet’s Job Read explicit data sent by client (form data) Read implicit data sent by client (request headers) Generate the results Send the explicit.
CSCI 6962: Server-side Design and Programming History and Background.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
Chapter 91© copyright Janson Industries 2011 Java Design Concepts ■ JSP’s ■ MVC MVC ■ Beans Beans ■ JSP Tags JSP Tags.
Session Beans Overview EJB container Remote Invocation Represent client's access to app Local / Remote speed / flexibility trade-off when to choose local.
Chapter 111© copyright Janson Industries 2011 Custom Tags ▮ Tag Handlers ▮ XML ▮ Tag Libraries ▮ Web Deployment Descriptor.
CSC 2720 Building Web Applications
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.
DataBases and SQL INFSY 547 Spring Course Wrap Up April 12: Complete Work on Servlets Review of Team Projects Close of Portfolio Work April 19:
Servlet / JSP 전 혜 영전 혜 영 전 혜 영전 혜 영. 0. 목차  Web Application Technologies  Servlet Server  Simple Servlet  Servlet / HTML Form  Deployment Descriptor.
CGS – 4854 Summer 2012 Web Site Construction and Management Instructor: Francisco R. Ortega Chapter 2.
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.
Mark Dixon 1 09 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
The Simplest Possible Tool - Iteration 1 Vancouver Bootcamp Mike Osterman
Servlet Communication Other Servlets, HTML pages, objects shared among servlets on same server Servlets on another server with HTTP request of the other.
이경화 Ch13. 웹 프로그래밍 설계 및 실습 MVC2 Member.
20-Nov-15introServlets.ppt Intro to servlets. 20-Nov-15introServlets.ppt typical web page – source Hello Hello.
Top right corner for field-mark, customer or partner logotypes. See Best practice for example. Slide title 40 pt Slide subtitle 24 pt Text 24 pt Bullets.
Li Tak Sing COMPS311F. A web page that counts the number of times that you have visited the page. You can try the page at:
CSE 403 The Mythical Servlet Goals Introduce basic servlet terminology Formally introduce homework 2 Walkthrough of build & deployment Group discussion.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
Mark Dixon 1 11 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
Configuration Web Server Tomcat - Install JDK Install Tom cat Configure Tom cat for running Servlet C:\Program Files\Apache Software Foundation\Tomcat.
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
Java and the Web CSE 3330 Southern Methodist University.
Introduction To HTML Dr. Magdi AMER. HTML elements.
ClaRA web services V. Gyurjyan Clas12 Software Meeting
How CGI and Java Servlets are Run By David Stein 14 November 2006.
J2EE/Java EE Apache Tomcat v9 IBM Websphere v8 Redhat JBoss EAP v6 Oracle Weblogic v12 Fusion Web Tier ServletsJSPJSF Business Tier JMXJMSEJB.
OOSD Using Java CBTS Framework. 11/2/04CBTS2 Servlet  A servlet is a Java program that can extends Web server’s functionality.  Servlets interact with.
Struct-like structure. Controller extends HttpServlet //Process the HTTP Get request public void doGet(HttpServletRequest request, HttpServletResponse.
Introduction to Servlets
Principles of Software Development
Handling Errors in Web Applications
PERTEMUAN 3.
Servlet Fudamentals.
Net-centric Computing
Session Tracking in Servlets
HTTP Servlet Overview Servlets are modules that extend request/response-oriented servers, such as Java-enabled web servers. For example, a servlet might.
V. Gyurjyan Clas12 Software Meeting
SERVLETS AND JDBC.
In Class Assg 3 - Solution
Jagdish Gangolly State University of New York at Albany
Servlets and JSP 20-Nov-18 servletsJSP.ppt.
Servlets & JSP.
In Class Assg 2 - solution
© copyright Janson Industries 2011
© copyright Janson Industries 2011
© 2014, Mike Murach & Associates, Inc.
COP 4610L: Applications in the Enterprise Spring 2005
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
Introduction to Java Servlets
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
CS122B: Projects in Databases and Web Applications Winter 2019
Basic servlet structure
Presentation transcript:

In Class Assg 4 - Solution co Func2 Servlet Customer object Creates Cust.html Creates co request response User Retrieves info HTML (response) With Cust info Cust Servlet Chapter 8 © copyright Janson Industries 2011

In Class Assg 4 - Solution import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class CustServlet extends HttpServlet { private static final long serialVersionUID = 1L; public CustServlet() { super(); } Chapter 8 © copyright Janson Industries 2011

© copyright Janson Industries 2011 protected void doGet(HttpServletRequest req, HttpServletResponse resp, Customer cust) throws ServletException, IOException { resp.setContentType("text/html"); try { PrintWriter out = new PrintWriter(resp.getOutputStream()); out.println("<HTML>"); out.println("<HEAD><Title>Servlet Response</Title></HEAD>"); out.println("<BODY>"); out.println("The customer name is: " + cust.getCustName() + "<BR>"); out.println("The street is: " + cust.getShipToStreet() + "<BR>"); out.println("The city is: " + cust.getShipToCity() + "<BR>"); out.println("The state is: " + cust.getShipToState() + "<BR>"); out.println("The zip is: " + cust.getShipToZip() + "<BR>"); out.println("The contact person is: "+cust.getContactPerson()+"<BR>"); out.println("The phone number is: “ +cust.getContactPhone()+"<BR>"); out.println("</BODY>"); out.println("</HTML>"); out.close(); } catch (Exception e) { System.out.println("Sample Servlet failed: "); e.printStackTrace(); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Chapter 8 © copyright Janson Industries 2011

In Class Assg 4 - Solution import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class Func2Servlet extends HttpServlet { private static final long serialVersionUID = 1L; Customer co = new Customer(); public Func2Servlet() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Chapter 8 © copyright Janson Industries 2011

In Class Assg 4 - Solution protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { co.setCustName(request.getParameter("CustName")); co.setShipToStreet(request.getParameter("Street")); co.setShipToCity(request.getParameter("City")); co.setShipToState(request.getParameter("State")); co.setShipToZip(request.getParameter("Zip")); co.setContactPerson(request.getParameter("ContactPerson")); co.setContactPhone(request.getParameter("PhoneNum")); CustServlet cs = new CustServlet(); cs.doGet(request, response, co); } Don’t forget to change Cust.html to invoke Func2Servlet Chapter 8 © copyright Janson Industries 2011