Servlet Java Tutorial

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class MyServlet extends HttpServlet {
   
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {
    
    Cookie cookie = null;
    //Get an array of Cookies associated with this domain
    Cookie[] cookies = request.getCookies();
    boolean hasCookies = false;
    
  if (cookies != null)
        hasCookies = true;
   
        // display the name/value of each cookie
        response.setContentType("text/html");
        java.io.PrintWriter out = response.getWriter();
    
        out.println("");
        out.println("");
        out.println("Cookie information");  
        out.println("");
        out.println("");
        if (hasCookies){
        out.println("

 The name and value of each found cookie

");
        
         for (int i = 0; i < cookies.length; i++){
            cookie = cookies[i];
            out.println("Name of cookie #"+(i + 1)+": "+cookie.getName()+"
");
            out.println("Value of cookie #"+(i + 1)+": "+cookie.getValue()+"

");
      
       }
        
        } else {
            out.println("

 This request did not include any cookies

");
        }
      
        out.println("");
        out.println("");
    
        out.close();
    } 
    
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {
        
        doGet(request,response);
    } 
}


    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
    "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

    MyServletName
             MyServlet
        
            
                go
            

            
                weather
            

        

             
    

    
    MyServletName
        /index.html