Академический Документы
Профессиональный Документы
Культура Документы
5 3 4 | 6 7 8 | 9 1 2 6 7 2 | 1 9 5 | 3 4 8 1 9 8 | 3 4 2 | 5 6 7 -------+-------+-----8 5 9 | 7 6 1 | 4 2 3 4 2 6 | 8 5 3 | 7 9 1 7 1 3 | 9 2 4 | 8 5 6 -------+-------+-----9 6 1 | 5 3 7 | 2 8 4 2 8 7 | 4 1 9 | 6 3 5 3 4 5 | 2 8 6 | 1 7 9
02.11.2005
02.11.2005
Podcasts
Became popular in late 2004 i-Pod, broadcast
3
02.11.2005
02.11.2005
Today
Servlets in context Java Server Pages Custom socket programming
02.11.2005
02.11.2005
02.11.2005
JSP
Java Server Pages 2.0 (JSR-152), 24 Nov 2003 Java Server Pages 2.1 (JSR-245), Proposed Final Draft 25 Aug, 2005
Servlet/JSP Spec Apache Tomcat version 2.4/2.0 5.5.12 2.3/1.2 4.1.31 2.2/1.1 3.3.2
02.11.2005
02.11.2005
10
JSP Lifecycle
Similar to Servlets after being compiled
JSP Lifecycle
1. Compilation
1. JSP engine checks if compilation is needed 2. First the page is parsed turned into a servlet 3. The servlet is then compiled 4. If you want to bypass compilation, you can also compile manually (precompile)
02.11.2005
11
02.11.2005
12
JSP Lifecycle
2. Loading
1. As JSP essentially becomes a servlet it is loaded as a servlet would be 2. If a newer version of the JSP source file is found, the class file may be reloaded 3. ! Although the class file gets loaded the other utility classes might not be it depends on the JSP engine
JSP Lifecycle
3. Initialization
1. Servlets init() should not be overriden, jspInit() might be instead 2. You can use
<servlet> <servlet-name>HelloWorldJSP</servlet-name> <jsp-file>/HelloWorld.jsp</jsp-file> ... </servlet>
02.11.2005
13
02.11.2005
14
JSP Lifecycle
4. Execution
1. JSP engine invokes the jspService() method each time a request is made by the browser
JSP contents
Directives control how the engine generates the servlet
<%@ include file="somefile.ext" %>
5. Cleanup
1. The cleanup happens through jspDestroy()
include page
import contentType errorPage isErrorPage isThreadSafe
taglib
02.11.2005 Lecture 8 / Andres Teder 15 02.11.2005 Lecture 8 / Andres Teder 16
JSP contents
Scripting elements allow java code to directly be entered into the servlet
<%= Hello world" %>
02.11.2005
17
02.11.2005
18
JSP 2.0
Requires JDK 1.3 for standalone containers and JDK 1.4 for J2EE containers Uses Servlet 2.4 specification for web semantics Simple expression language added Simple invocation protocol added
19 02.11.2005 Lecture 8 / Andres Teder 20
02.11.2005
JSP 2.1
Includes a unified expression language the result of integrating JSP 2.0 and Faces 1.1 specification expression languages Uses Servlet 2.5 specification Requires JDK 1.5
After
${aCustomer.address.country}
02.11.2005
21
02.11.2005
22
Custom tags
JSP Tag Extension API
1. Write a Java class that implements one of the Tag interfaces (Tag, IterationTag, BodyTag)
1. Tag basic methods for all tag handlers 2. IterationTag extension to Tag, provides doAfterBody 3. BodyTag extension to IterationTag, provides tag body manipulation
02.11.2005
POST - request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line
Includes a message body (key;value pairs)
02.11.2005 Lecture 8 / Andres Teder 29 02.11.2005 Lecture 8 / Andres Teder 30
02.11.2005
31
Servlet frameworks
Consider
The licence (GPL, LGPL, ) The feature list (Security, Persitence integration, Display technologies, ) The target group (Ecommerce sites, Portals, )
Port not a physical device, but an abstraction to facilitate communication between the client and the server Socket - an abstraction for the network software that enables communication out of and into this program
02.11.2005
33
02.11.2005
34
Socket
Connection between two hosts
Connecting to a remote machine Sending data Receiving data Closing a connection Binding to a port Listening for incoming data Accepting connections from remote machines on the bound port
35 02.11.2005 Lecture 8 / Andres Teder 36
Datagrams are split across mutliple packets Sockets give an abstract view on network connections
02.11.2005 Lecture 8 / Andres Teder
Sockets in Java
1. Create a new socket with java.net.Socket() 2. The socket attempts to connect to the remote server 3. When the connection is established socketObj.getOutputStream() socketObj.getInputStream() Connection is full-duplex 4. Connection is closed (HTTP 1.0) after every request or can be left open (FTP)
java.net.Socket
Fundamental class for client-side TCP operations Different other classes URL, URLConnection, Applet end up using this class Socket(host,port)
Host = InetAddress or a String Port = int up to 65535
If opening sockets many times to the same host it is more efficient to reuse InetAddress
37 02.11.2005 Lecture 8 / Andres Teder 38
02.11.2005
java.net.Socket
Socket(host,port,interface,localport) Obtaining information about sockets:
getInetAddress() getLocalPort()
java.net.Socket
If you want to only close one type of stream:
shutdownInput() shutdownOutput()
02.11.2005
Socket properties
TCP_NODELAY packets sent as quickly as possible regardless of their size
Nagles Algorithm - as long as there is an sent packet for which the sender has received no acknowledgement, the sender should keep buffering its output until it has a full packet' s worth of output
Socket properties
SO_LINGER specifies what to do with datagrams that have not been sent when the socket is closed. Can specify a linger time (maximum is platform specific) SO_TIMEOUT the timeout for the read(), needs to be set before the blocking operation SO_RCVBUF, SO_SNDBUF the buffer size of the TCP stack
02.11.2005 Lecture 8 / Andres Teder 42
02.11.2005
41
Socket properties
SO_KEEPALIVE when set, the client periodically sends an alive packet to make sure the server has not crashed SO_REUSEADDR -allows the server to bind to a port which is in TIME_WAIT state
02.11.2005 Lecture 8 / Andres Teder 43
Socket properties
OOBINLINE (Out of Band Data) reception of TCP urgent data, operating system interrupts the receiving process if this process has chosen to be notified about out-of-band data. Can decrease the performance of the server.
02.11.2005
44
Server-side Sockets
java.net.ServerSocket 1. ServerSocket() is created on a particular port 2. Waits for connections using accept() 3. Communicates via Input/Output streams 4. Server, client or both close the connection 5. The server returns to step 2
02.11.2005 Lecture 8 / Andres Teder 45
Server Sockets
Incoming connections stored in a queue by the operating systems ServerSocket(port) ServerSocket(port,queuelength) ServerSocker(port,queuelength,bindaddre ss)
02.11.2005
46
Secure Sockets
Java Secure Sockets Extension (JSSE) - a set of packages that enable secure Internet communications Included since JDK 1.4.x Optional package in older JDKs
02.11.2005
47
02.11.2005
48
Secure Sockets
SSL standard protocol proposed by Netscape for implementing cryptography SSL has two aims:
Authenticate the server and client using public key signatures and digital certificates Provide an encrypted connection for the client and server to exchange messages securely
Secure sockets
SSL uses symmetric (same key used to encrypt and decrypt) cryptography for data encryption SSL uses asymmetric or public key cryptography to authenticate the identities of the communicating parties and encrypt the session key when establishing session
02.11.2005
49
02.11.2005
50
SSL
Record protocol way in which messages passed between the client and server are encapsulated. Has a cipher suite associated. Cipher suite determines -The kind of key exchange algorithm used -The encryption algorithm used -The digest algorithm used Handshake protocol used to negotiate the type of connection the client and server can support, perform authentication and generate a bulk encr
02.11.2005
51
02.11.2005
52
SSL Handshake
SSL
More detailed view
02.11.2005
53
02.11.2005
54
Secure Sockets
SSLSocketFactory
createSocket(Socket s, String host, int port, boolean autoClose)
SSLServerSocketFactory
createSocket(Socket s, String host, int port, boolean autoClose)
02.11.2005
55
02.11.2005
56
Letters may arrive or not The order of arrival is not fixed The further you are the most likely is the loss of mail
02.11.2005
57
02.11.2005
58
Datagram Socket
Options: SO_RCVBUF, SO_SNDBUF, SO_REUSEADDR, SO_TIMEOUT SO_BROADCAST - enables and disables the ability of the process to send broadcast messages
60
Multicast Sockets
Unicast point to point Multicast broader than point to point but narrower than broadcast data goes to many hosts, but only to those who have shown interest Built on top of UDP In Java - MultiCastSocket
02.11.2005 Lecture 8 / Andres Teder 61
Multicasting
Useful when connecting many agents together on a common communication channel Audio,Video (videoconference) Multiplayer games Distributed Filesystems Database replication
Lecture 8 / Andres Teder 62
02.11.2005
MulticastSocket
1. 2. 3. 4. 5. Create socket Join a multicast group Send data to the members of the group Receive data from the group Leave multicast group
MulticastSocket
MulticastSocket ms = new MulticastSocket(); InetAddress sessAddr = InetAddress.getByName("224.2.76.24"); ms.joinGroup(sessAddr); ms.receive(DatagramPacket) ms.send() ms.leaveGroup(sessAddr)
02.11.2005
63
02.11.2005
64
Summary
Finished overview of Servlets Overview of JSP Custom sockets over TCP Secure sockets Custom sockets over UDP Multicasting
02.11.2005
65