

import java.io.IOException;
import java.util.Map;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class for Servlet: Profile
 *
 */
 public class Octopus extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
   static final long serialVersionUID = 1L;
   
    /* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public Octopus() {
		super();
	}   	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String uri;
		//String base;
		String call;
		uri = request.getRequestURI();
		//base= request.getContextPath();
		
		String tableau[] = uri.split("/");
		if(tableau[tableau.length - 1].isEmpty()) {
		//	System.out.println("erreur");
			call = null;
		}
		else {
			call = tableau[2];
		//	System.out.println("Chemin: " + call);
		}
		
		Map parameterList;
		parameterList = request.getParameterMap();
		if(parameterList.size() > 0){
		//	System.out.println(request.getParameter("nom"));
		}
		
		// System.out.println("Base du site: " + base);
		
		String redirect = "/index.jsp";
		
		if (call != null) {
		}
		else if (call == "contacts")
		{
			redirect = "/index.jsp";
		}
		else {
			redirect = "/error.jsp";
		}
		
		ServletContext ctx = getServletContext();
		RequestDispatcher rd = ctx.getRequestDispatcher(redirect.toString());
		rd.forward(request,response);
	}  	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}   	  	    
}