J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.

Slides:



Advertisements
Similar presentations
Chapter 6 Server-side Programming: Java Servlets
Advertisements

4 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: Servlets.
JLab Lattice Portal – Data Grid Web Service Ying Chen, Chip Watson Thomas Jefferson National Accelerator Facility.
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
HTTP Requests & Responses1 Servlets: HTTP Request Header Contents and Responses.
Introduction to Servlets Based on: Hall, Brown, Core Servlets and JavaServer Pages.
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.
Core servlets chapter 6 Generating server response: http status codes.
HTTP – HyperText Transfer Protocol
An introduction to Java Servlet Programming
CS320 Web and Internet Programming Generating HTTP Responses
HTTP Response Headers Vijayan Sugumaran Department of DIS Oakland University Parts of this presentation was provided by
MVC Architecture1 Usage Rules PowerPoint slides for use only in for-credit courses at degree-granting institutions Slides can be modified.
Integrating Servlets and JavaServer Pages Vijayan Sugumaran School of Business Administration Oakland University Parts of this presentation provided by.
2/9/2004 Web and HTTP February 9, /9/2004 Assignments Due – Reading and Warmup Work on Message of the Day.
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.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
J2EE training: 1 TODO Replace Netscape examples with Firefox. In later two sections also.
FTP (File Transfer Protocol) & Telnet
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
Java Omar Rana University of South Asia. Course Overview JAVA  C/C++ and JAVA Comparison  OOP in JAVA  Exception Handling  Streams  Graphics User.
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
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.
Li Tak Sing COMPS311F. Static attributes in Servlets Since Servlets are also Java classes, you can also use static attributes to store values that can.
JSP Architecture Outline  Model 1 Architecture  Model 2 Architecture.
COMP 321 Week 7. Overview HTML and HTTP Basics Dynamic Web Content ServletsMVC Tomcat in Eclipse Demonstration Lab 7-1 Introduction.
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
Chapter 5 HTTP Request Headers. Content 1.Request headers 2.Reading Request Headers 3.Making a Table of All Request Headers 4.Sending Compressed Web Pages.
Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some.
Slides © Marty Hall, book © Sun Microsystems Press 1 Generating the HTTP Response Core Servlets & JSP book:
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.
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
Saving Client State Session Tracking: Maintain state about series of requests from same client over time Using Cookies: Clients hold small amount of their.
1-1 HTTP request message GET /somedir/page.html HTTP/1.1 Host: User-agent: Mozilla/4.0 Connection: close Accept-language:fr request.
20-Nov-15introServlets.ppt Intro to servlets. 20-Nov-15introServlets.ppt typical web page – source Hello Hello.
 Obtaining a RequestDispatcher Forwarding requests from servlets to dynamic resources  Forwarding requests from servlets to static resources  Using.
Slides © Marty Hall, book © Sun Microsystems Press 1 Handling Cookies Core Servlets & JSP book: More.
Appendix E: Overview of HTTP ©SoftMoore ConsultingSlide 1.
Java Servlets and Java Server Pages Norman White Stern School of Business.
Copyright © 2002 ProsoftTraining. All rights reserved. Java Servlets.
Operating Systems Lesson 12. HTTP vs HTML HTML: hypertext markup language ◦ Definitions of tags that are added to Web documents to control their appearance.
Hints for Assignment #8. Initial Screen Hints for the initial page You need a DOCTYPE with the proper namespaces defined You need to import the facebook.
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.
© Marty Hall, Larry Brown Web core programming 1 Using Applets as Front Ends to Server-Side Programs.
1 Web Programming with Servlets & JSP ASSIGNMENT GUIDELINE.
Slides © Marty Hall, book © Sun Microsystems Press 1 Session Tracking Core Servlets & JSP book: More.
SKT-SSU IT Training Center Servlet and JSP. Chapter Seven: Generating the Server Response: HTTP Response Headers.
Advanced Java Session 6 New York University School of Continuing and Professional Studies.
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
COMP2322 Lab 2 HTTP Steven Lee Jan. 29, HTTP Hypertext Transfer Protocol Web’s application layer protocol Client/server model – Client (browser):
How CGI and Java Servlets are Run By David Stein 14 November 2006.
 Java Server Pages (JSP) By Offir Golan. What is JSP?  A technology that allows for the creation of dynamically generated web pages based on HTML, XML,
Using Applets as Front Ends to Server-Side Programs.
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.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
CS 562 Advanced Java and Internet Application Computer Warehouse Web Application By Team Alpha :-  Puja Mehta (102163)  Mona Nagpure (102147)
Introduction to Servlets
Handling Errors in Web Applications
CS320 Web and Internet Programming Generating HTTP Responses
Generating the Server Response: HTTP Status Codes
In Class Assg 2 - solution
Presentation transcript:

J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting institutions –Slides not permitted for use in commercial training courses except when taught by coreservlets.com (see Slides can be modified however instructor desires Instructor can give PDF or hardcopy to students, but should protect the PowerPoint files –This slide is suppressed in Slide Show mode

JSP, Servlet, Struts, JSF & Java Training: J2EE Books from Sun Press: © 2005 Marty Hall 2 Generating the Server Response: HTTP Status Codes

J2EE training: 3 Agenda Format of the HTTP response How to set status codes What the status codes are good for Shortcut methods for redirection and error pages A servlet that redirects users to browser- specific pages A front end to various search engines

J2EE training: 4 HTTP Request/Response Request GET /servlet/SomeName HTTP/1.1 Host:... Header2: HeaderN: (Blank Line) Response HTTP/ OK Content-Type: text/html Header2: HeaderN:... (Blank Line)......

J2EE training: 5 Setting Status Codes response.setStatus(int statusCode) –Use a constant for the code, not an explicit int. Constants are in HttpServletResponse –Names derived from standard message. E.g., SC_OK, SC_NOT_FOUND, etc. response.sendError(int code, String message) –Wraps message inside small HTML document response.sendRedirect(String url) –Sets status code to 302 –Sets Location response header also

J2EE training: 6 Common HTTP 1.1 Status Codes 200 (OK) –Everything is fine; document follows. –Default for servlets. 204 (No Content) –Browser should keep displaying previous document. 301 (Moved Permanently) –Requested document permanently moved elsewhere (indicated in Location header). –Browsers go to new location automatically. –Browsers are technically supposed to follow 301 and 302 (next page) requests only when the incoming request is GET, but do it for POST with 303. Either way, the Location URL is retrieved with GET.

J2EE training: 7 Common HTTP 1.1 Status Codes (Continued) 302 (Found) –Requested document temporarily moved elsewhere (indicated in Location header). –Browsers go to new location automatically. –Servlets should use sendRedirect, not setStatus, when setting this header. See example. 401 (Unauthorized) –Browser tried to access password-protected page without proper Authorization header. 404 (Not Found) –No such page. Servlets should use sendError to set this. –Problem: Internet Explorer and small (< 512 bytes) error pages. IE ignores small error page by default. –Fun and games:

J2EE training: 8 A Servlet That Redirects Users to Browser-Specific Pages public class WrongDestination extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String userAgent = request.getHeader("User-Agent"); if ((userAgent != null) && (userAgent.indexOf("MSIE") != -1)) { response.sendRedirect(" } else { response.sendRedirect(" }

J2EE training: 9 A Servlet That Redirects Users to Browser-Specific Pages

J2EE training: 10 A Front End to Various Search Engines public class SearchEngines extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String searchString = request.getParameter("searchString"); if ((searchString == null) || (searchString.length() == 0)) { reportProblem(response, "Missing search string"); return; } searchString = URLEncoder.encode(searchString); String searchEngineName = request.getParameter("searchEngine"); if ((searchEngineName == null) || (searchEngineName.length() == 0)) { reportProblem(response, "Missing search engine name"); return; }

J2EE training: 11 A Front End to Various Search Engines (Continued) String searchURL = SearchUtilities.makeURL(searchEngineName, searchString); if (searchURL != null) { response.sendRedirect(searchURL); } else { reportProblem(response, "Unrecognized search engine"); } private void reportProblem(HttpServletResponse response, String message) throws IOException { response.sendError(response.SC_NOT_FOUND, message); }

J2EE training: 12 A Front End to Various Search Engines (Continued) public class SearchSpec { /** Builds a URL for the results page by * simply concatenating the base URL * ( with the * URL-encoded search string (jsp+training). */ public String makeURL(String searchString) { return(baseURL + searchString); } … }

J2EE training: 13 Front End to Search Engines: HTML Form

J2EE training: 14 Front End to Search Engines: Result for Valid Data

J2EE training: 15 Front End to Search Engines: Result for Invalid Data

J2EE training: 16 Summary Many servlet tasks can only be accomplished through use of HTTP status codes Setting status codes: –In general, set via response.setStatus –In special cases (302 and 404), set with response.sendRedirect and response.sendError Most important status codes –200 (default) –302 (forwarding; set with sendRedirect) –401 (password needed) –404 (not found; set with sendError)

JSP, Servlet, Struts, JSF & Java Training: J2EE Books from Sun Press: © 2005 Marty Hall 17 Questions?