import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ECHOServlet2 extends HttpServlet
{
	private static final long serialVersionUID = 1L;
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException
	{
			String title = "Servlet ECHO";
			String doctype = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Strict//EN\" \"http://www.w3.org/TR/html4/strict.dtd\"> "; // DOCTYPE HTML 4.0
			
			response.setContentType("text/html");
			PrintWriter out = response.getWriter();
			
			out.println(doctype+
					"<html>\n<head><title>" + title + "</title></head>\n" +
					"<body>\n<h1 style=\"color:DarkSlateGray\"><center>" + title + "</center></h1>\n" +
					"<b style=\"color:DarkSlateBlue\"><u>Request Method:</u></b>\n\n" + "<span style=\"color:red\">" + request.getMethod()+ "</span>" + "<br />\n" +
					"<b style=\"color:DarkSlateBlue\"><u>Request URI:</u></b>\n\n"+ "<span style=\"color:red\">"  + request.getRequestURI()+ "</span>" + "<br />\n" +
					"<b style=\"color:DarkSlateBlue\"><u>Request Protocol:</u></b>\n\n"+ "<span style=\"color:red\">"  + request.getProtocol()+ "</span>" + "<br />\n" + "<br />\n" + "<br />");
			
			out.println("<b style=\"color:DarkSlateBlue\"><u>Query String: </u></b>"+ "<span style=\"color:red\">" + request.getQueryString() + "</span>" + "<br />");
			
			Enumeration<?> paramNames = request.getParameterNames();
				if(!paramNames.hasMoreElements()) out.println("<center><br />Pas de paramètres !!<br /></center>");
				else
				{
					out.println("<table border=2px bordercolor=\"black\" align=\"center\" bgcolor=\"NavajoWhite\">"
							+	"<tr bgcolor=\"#993333\">" +
							"<th align=\"center\"  style=\"color:white\"><b>Parameter Name</b></th>" +
							"<th align=\"center\"  style=\"color:white\"><b>Parameter Value</b></th>" +
						"</tr>");
					while(paramNames.hasMoreElements())
					{
						String param = (String)paramNames.nextElement();
						out.println("<tr align=\"center\"><td style=\"color:MidnightBlue\">" + param + "</td>");
						String[]paramValues=request.getParameterValues(param);
						String paramValuesString="";
						for(int i=0;i<paramValues.length;i++)
						{
							paramValuesString+=paramValues[i]+";";
						}
						out.println("<td>" + paramValuesString + "</td></tr>");
					}
				}
			out.println("</table>\n</body></html>");
			out.close();
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException
	{
		doGet(request,response);
	}
}