Social Java Social Application development using Java



SocialJavaGetAndPost Application: Description:
This example shows whether get or post is called and displayes servlet parameters


Prerequisites: The Java Code :
Download Source
import javax.servlet.http.*;
import java.io.IOException;
import javax.servlet.*;
import java.io.PrintWriter;
import java.util.Enumeration;  // add enumeration 


public class SocialJavaGetAndPost extends HttpServlet {
	PrintWriter servletOutput;

	public void doGet(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		servletOutput = res.getWriter();
		res.setContentType("text/html");
		servletOutput.println("This is the doGet method");
	}

	public void doPost(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		servletOutput = res.getWriter();
		res.setContentType("text/html");
		servletOutput.println("This is the doPost method");
	    //    Extend to print all parms and values
        //    google snoopservlet
        Enumeration e = req.getParameterNames();
    	if (e.hasMoreElements()) {
    		 servletOutput.println("<h1>Servlet parameters (Single Value style):</h1>");
    		 servletOutput.println("<pre>");
    	    while (e.hasMoreElements()) {
    		String name = (String)e.nextElement();
    		 servletOutput.println(" " + name + " = " + req.getParameter(name));
    	    }
    	    servletOutput.println("</pre>");
    	}		
	}
}


This is what is seen after adding the application in Facebook:

SocialJavaGetAndPost Screenshot