DOC PREVIEW
CMU ISM 95702 - An Introduction to Servlet Programming

This preview shows page 1-2-3-4-24-25-26-50-51-52-53 out of 53 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

95-702 Distributed SystemsWhat is a Servlet?Servlet LifecycleWhat is an HTTP request?What is an HTTP Response?Request Reply PatternSlide 7Reading Form Data With Servlets Under a Web Server (Glassfish)Slide 9Slide 10Slide 11Slide 12Slide 13NetBeans Project ListNetBeans Generated web.xmlSome Non-Functional CharacteristicsHandling CheckBoxesPizza ToppingsServlet ResponsePizzaData ServletSlide 21Slide 22Slide 23Slide 24Part II Session Tracking and Servlet CollaborationSession Tracking with ServletsTraditional Session TrackingUser AuthorizationShared ObjectsVisitTracker.javaSlide 31Slide 32Slide 33Slide 34Slide 35GlassFish Web.xml (1)GlassFish Web.xml (2)GlassFish Web.xml (3)Sun-web.xmlindex.jspSlide 41Slide 42Slide 43Slide 44HTTP CookiesUsing CookiesSlide 47Slide 48Slide 49The New Session Tracking APIThe Session Tracking APISlide 52Slide 5395-702 Distributed Systems1Master of Information System Management95-702 Distributed SystemsDay 2: An Introduction to Servlet Programming95-702 Distributed Systems2Master of Information System Management2Master of Information System ManagementWhat is a Servlet?•Created by Sun back in 1997 •A Java class that extends HttpServlet•Responds to HTTP requests•The response is usually XHTML or some other XML language •May maintain state across several interactions (may use cookies or URL rewriting or hidden form fields) •Live within a web container•May be generated by a JSP compiler95-702 Distributed Systems3Master of Information System ManagementServlet Lifecycle•The container loads the servlet class.•The servlet’s init() method is called exactly once.•Upon each request, the container calls the servlet’s service() method.•The service() method selects the appropriate method to call and calls it.•Finally, before the container shuts down, it calls the servlet’s destroy() method.3Master of Information System Management95-702 Distributed Systems4Master of Information System ManagementWhat is an HTTP request?/* From Core Servlets, Marty HallAn HTTP Request header example GET /path/file.html HTTP/1.0 The whitespace is required. Accept: text/html Accept header fields Accept: audio/x tell the server MIME types User-agent: MacWeb (Multipurpose Internet Mail Extension) that are handled by the browser.HTTP defines dozens of possible headers. A blank line followed by name value pairs or an XML document95-702 Distributed Systems5Master of Information System ManagementWhat is an HTTP Response?An HTTP Response header example HTTP 1.0 200 OKServer: NCSA/1.4.2MIME-version: 1.0Content-type: text/htmlContent-length: 107<html>::</html>Blank lineMIME typeThe client must interpretthis MIME encoded data.Response code95-702 Distributed Systems6Master of Information System ManagementRequest Reply PatternRequest Request ChannelReply channel replyRequestorReplierThe pattern applies in the asynchronous and synchronous cases.HTTP is synchronous request reply. From “Enterprise Integration Patterns”.95-702 Distributed Systems7Master of Information System Management HTTP General Form <method> <resource identifier> <HTTP Version> <crlf> [<Header> : <value>] <crlf> : : : [<Header> : <value>] <crlf> a blank line [entity body]The resource identifier field specifies the name of the targetresource; it's the URL stripped of the protocol and the serverdomain name. When using the GET method, this field will alsocontain a series of name=value pairs separated by ‘&’. When usinga POST method, the entity body contains these pairs.The HTTP version identifies the protocol used by the client.95-702 Distributed Systems8Master of Information System ManagementReading Form Data With Servlets Under a Web Server (Glassfish)// QueryData.java -- Handle the voting form in radio.htmlimport java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class QueryData extends HttpServlet { public void doPost(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException { doGet(req, response); }95-702 Distributed Systems9Master of Information System Management public void doGet(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException { String newPresident = req.getParameter("president"); response.setContentType("text/html"); PrintWriter out = response.getWriter(); String docType = "<!DOCTYPE HTML PUBLIC \"//W3C//DTD” + “HTML 4.0 "; docType += "Transitional//EN\">\n";95-702 Distributed Systems10Master of Information System Managementout.println(docType + "<HTML>\n" + "<HEAD><TITLE>Presidential Servlet" + "</TITLE>” + “</HEAD>\n" + "<BODY>\n" + "<H1>The new president is "+ newPresident + "</H1>\n" + "</BODY></HTML>"); }}95-702 Distributed Systems11Master of Information System Management<!-- index.jsp --><html><head><title>Radio Buttons</title></head><body BGCOLOR="WHITE"> <form action="http://localhost:8080/WeekTwoServlets/QueryData"> <dl> <dt> Please Vote </dt> <dd><Input type = "Radio" name = "president" value= "Bush"> <b>George W. Bush</b> <dd><Input type = "Radio" name = "president" value = "Gore"> Al Gore <dd><Input type = "Radio" name = "president" value = "Buchanan"> Pat Buchanan <dd><Input type = "Radio" name = "president" value = "Nader"> Ralph Nader <p> <input type = "submit"> </dl> </form></body></html>servletWeb server’s portProject path95-702 Distributed Systems12Master of Information System ManagementRadio HTML in the browser95-702 Distributed Systems13Master of Information System ManagementThe Servlet’s Response95-702 Distributed Systems14Master of Information System ManagementNetBeans Project ListNetbeans provides a development environment.The software is deployedto Glassfish.95-702 Distributed Systems15Master of Information System ManagementNetBeans Generated web.xmlNote how the servlet’sname is associated witha URL pattern.“QueryData” is auser defined identifier for use only within this file. <?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"


View Full Document

CMU ISM 95702 - An Introduction to Servlet Programming

Documents in this Course
Homework

Homework

12 pages

Lecture

Lecture

25 pages

Lecture

Lecture

21 pages

Lecture

Lecture

24 pages

Exam

Exam

11 pages

Homework

Homework

16 pages

Homework

Homework

38 pages

lecture

lecture

38 pages

review

review

7 pages

lecture

lecture

18 pages

review

review

8 pages

Chapter2

Chapter2

32 pages

Lecture 4

Lecture 4

47 pages

Lecture

Lecture

22 pages

Naming

Naming

26 pages

lecture

lecture

34 pages

lecture

lecture

42 pages

lecture

lecture

112 pages

Lecture

Lecture

33 pages

Axis

Axis

43 pages

lecture

lecture

32 pages

review

review

17 pages

Lecture

Lecture

53 pages

Lecture

Lecture

80 pages

Lab

Lab

14 pages

Load more
Download An Introduction to Servlet Programming
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view An Introduction to Servlet Programming and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view An Introduction to Servlet Programming 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?