DOC PREVIEW
CMU ISM 95702 - Sockets and Servlets

This preview shows page 1-2-3-4-5-36-37-38-39-40-72-73-74-75-76 out of 76 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 76 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 76 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 76 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 76 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 76 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 76 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 76 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 76 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 76 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 76 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 76 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 76 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 76 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 76 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 76 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 76 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Organizational Communications and Distributed Object TechnologiesJava ServletsPart I : Server and Servlet BasicsNetworkServer.javaPowerPoint PresentationSlide 6Slide 7Slide 8Compile, Run and VisitHTTP ServersHTTPSlide 12Request Reply PatternSlide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22PostForm.htmlPostForm.html BrowserEchoServer Response Using POSTGetForm.htmlGetForm.html BrowserEchoServer Response Using GETA Form With CheckboxesCheckBoxes BrowserCheckBox ResponseRadioBoxes HTMLRadioBoxes BrowserEchoServer ResponseReading Form Data With Servlets Under a Web Server (Glassfish)Slide 36Slide 37Slide 38Slide 39Slide 40NetBeans Project ListNetBeans Generated web.xmlHandling CheckBoxesPizza ToppingsServlet ResponsePizzaData ServletSlide 47Slide 48Slide 49Part II Session Tracking and Servlet CollaborationSession Tracking with ServletsTraditional Session TrackingUser AuthorizationShared ObjectsVisitTracker.javaSlide 56Slide 57Slide 58Slide 59Slide 60GlassFish Web.xml (1)GlassFish Web.xml (2)GlassFish Web.xml (3)Sun-web.xmlindex.jspSlide 66Slide 67Slide 68HTTP CookiesUsing CookiesSlide 71Slide 72Slide 73The New Session Tracking APIThe Session Tracking APISlide 76195-702 OCTMaster of Information System ManagementOrganizational Communications and Distributed Object TechnologiesWeek 2: Sockets and Servlets295-702 OCTMaster of Information System ManagementJava Servlets Part I Servers and Servlet Basics Part II Session Tracking and Servlet Collaboration395-702 OCTMaster of Information System ManagementPart I : Server and Servlet Basics•NetworkServer.java and EchoServer.java•PostForm.html•GetForm.html•More HTML form examples495-702 OCTMaster of Information System ManagementNetworkServer.java// NetworkServer.java Adapted from "Core Servlets// and Java Server Pages" // by Marty Hallimport java.net.*;import java.io.*;public class NetworkServer { private int port; private int maxConnections; No web server.Just this code.595-702 OCTMaster of Information System Management protected void setPort(int port) { this.port = port; } public int getPort() { return port; } protected void setMaxConnections(int max) { maxConnections = max; } public int getMaxConnections() { return maxConnections; } public NetworkServer(int port, int maxConnections) { setPort(port); setMaxConnections(maxConnections); }695-702 OCTMaster of Information System Management// Wait for a connections until maxConnections.// On each connection call handleConnection() passing// the socket. If maxConnections == 0 loop forever public void listen() { int i = 0; try { ServerSocket listener = new ServerSocket(port); Socket server ; while((i++ < maxConnections) || (maxConnections == 0)) { server = listener.accept(); // wait for connection handleConnection(server); } } catch (IOException ioe) { System.out.println("IOException : " + ioe); ioe.printStackTrace(); } }795-702 OCTMaster of Information System Management// Open readers and writers to socket.// Display client's host name to console.// Read a line from the client and display it on the console.// Send "Generic network server" to the client.// Override this method.protected void handleConnection(Socket server) throws IOException { BufferedReader in = new BufferedReader( new InputStreamReader( server.getInputStream() )); PrintWriter out = new PrintWriter( server.getOutputStream(),true); Flush bufferon printlnInputStream forreading bytesReaders and Writersto work with characters895-702 OCTMaster of Information System ManagementSystem.out.println("Generic network server: got connection from "+ server.getInetAddress().getHostName() + "\n" + "with first line '" + in.readLine() + "'"); out.println("Generic network server"); server.close(); } public static void main(String args[]) { NetworkServer test = new NetworkServer(6502, 5); test.listen(); }} To server’sconsole.To client.995-702 OCTMaster of Information System ManagementCompile, Run and VisitC:\McCarthy\www\46-928\examples\networking>java NetworkServerGeneric network server: got connection from localhostwith first line 'GET / HTTP/1.0'ClientServer1095-702 OCTMaster of Information System ManagementHTTP Servers• NetworkServer is using TCP/IP sockets.• The browser is sending an HTTP request and would usually receive an HTTP reply. NetworkServer only sends a string.• The HTTP reply would normally contain an HTML body.• Let’s add these features to a new NetworkServer. • We’ll call the new server “EchoServer.java”.• EchoServer will accept an HTTP request (as before).• It will take the request headers from the request.• It will respond with an HTTP response. The response will contain the request headers wrapped in HTML.1195-702 OCTMaster of Information System ManagementHTTP/* 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 document1295-702 OCTMaster of Information System ManagementHTTPAn 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 code1395-702 OCTMaster of Information System ManagementRequest Reply PatternQuickTime™ and a decompressorare needed to see this picture.Request Request ChannelReply channel replyRequestorReplierThe pattern applies in the asynchronous and synchronous cases.HTTP is synchronous request reply. From “Enterprise Integration Patterns”.1495-702 OCTMaster of Information System Management HTTP General Form <method> <resource identifier> <HTTP Version> <crlf> [<Header> : <value>] <crlf> : : : [<Header> :


View Full Document

CMU ISM 95702 - Sockets and Servlets

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 Sockets and Servlets
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 Sockets and Servlets 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 Sockets and Servlets 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?