HTTP and Java

URL

The class java.net.URL is designed to make it easier to handle fetching url data. You don't have to open sockets yourself

URLConnection

If you want to get extra information about the url, the class URLConnection can be used

Forms

HTTP connections write information from client to HTTP server and read the reply. This can be used to fetch static URLs (as above). It can also be used to post form data and read the reply. The URLConnection can be used for this

Authorization

Proxies

Proxy Authorization

Displaying URLs

Some classes that are useful on the client side for displaying documents

HTTP server

Server-side processing - Servlets

Servlet template


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class SomeServlet extends HttpServlet {
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
      throws ServletException, IOException {
      
    // Use "request" to read incoming HTTP headers (e.g. cookies)
    // and HTML form data (e.g. data the user entered and submitted)
    
    // Use "response" to specify the HTTP response line and headers
    // (e.g. specifying the content type, setting cookies).
    
    PrintWriter out = response.getWriter();
    // Use "out" to send content to browser
  }
}

HelloWorld servlet (plain text)

HelloWorld servlet (HTML)

Form parameters

Cookies

Session tracking


Jan Newmarch (http://jan.newmarch.name)
jan@newmarch.name
Last modified: Mon Aug 21 22:41:42 EST 2006
Copyright ©Jan Newmarch