content: package com.airxiechao.oarword;
  
  import java.io.IOException;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  
  /**
   * Servlet implementation class Ticket
   */
  public class NewFileName extends HttpServlet {
  	private static final long serialVersionUID = 1L;
         
      /**
       * @see HttpServlet#HttpServlet()
       */
      public NewFileName() {
          super();
          // TODO Auto-generated constructor stub
      }
  
  	/**
  	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  	 */
  	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  		Hall hall = (Hall) getServletContext().getAttribute("Hall");
  		
  		String ip = getClientIpAddr(request);
  		String file = request.getParameter("file");
  
  		if( file == null ) {
  			return;
  		}
  		
  		Ticket tik = new Ticket(ip, new String(file.getBytes("ISO-8859-1"), "UTF-8"));
  		hall.putTicket(tik);
  
  		/*
  		List<Ticket> all = hall.getTickets();
  		Iterator<Ticket> iter = all.iterator();
  		while( iter.hasNext() ) {
  			Ticket t = iter.next();
  			System.out.println(t.getIp() + " " + t.getTime() + " " + t.getFile());
  		}
  		*/
  	}
  
  	/**
  	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  	 */
  	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  		// TODO Auto-generated method stub
  	}
  	
  	public static String getClientIpAddr(HttpServletRequest request) {  
          String ip = request.getHeader("X-Forwarded-For");  
          
          if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
              ip = request.getHeader("Proxy-Client-IP");  
          }  
          if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
              ip = request.getHeader("WL-Proxy-Client-IP");  
          }  
          if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
              ip = request.getHeader("HTTP_CLIENT_IP");  
          }  
          if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
              ip = request.getHeader("HTTP_X_FORWARDED_FOR");  
          }  
          if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
              ip = request.getRemoteAddr();  
          }  
          
          return ip;  
      }  
  
  }
  