@@ -0,0 +1,2056 @@
+import javax.servlet.ServletException;%0Aimport javax.servlet.http.HttpServlet;%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0Aimport java.io.IOException;%0Aimport java.io.PrintWriter;%0A%0Apublic class LoginAndProcess extends HttpServlet %7B%0A%09public void doGet(HttpServletRequest request,%0A%09%09%09%09%09  HttpServletResponse response)%0A%09%09throws ServletException, IOException%0A%09%7B%0A%09%09generate(request,response);%0A%09%7D%0A%0A%09public void doPost(HttpServletRequest request,%0A%09%09%09%09%09   HttpServletResponse response)%0A%09%09throws ServletException, IOException%0A%09%7B%0A%09%09generate(request,response);%0A%09%7D%0A%0A%09public void generate(HttpServletRequest request,%0A%09%09%09%09%09%09 HttpServletResponse response)%0A%09%09throws ServletException, IOException%0A%09%7B%0A%09%09String event = request.getParameter(%22event%22);%0A%09%09if ( event==null %7C%7C event.equals(%22view%22) ) %7B%0A%09%09%09view(request,response);%0A%09%09%7D%0A%09%09else %7B%0A%09%09%09process(request,response);%0A%09%09%7D%0A%09%7D%0A%0A%09public void view(HttpServletRequest request,%0A%09%09%09%09%09 HttpServletResponse response)%0A%09%09throws ServletException, IOException%0A%09%7B%0A%09%09response.setContentType(%22text/html%22);%0A%09%09PrintWriter out = response.getWriter();%0A%09%09out.println(%22%3Chtml%3E%22);%0A%09%09out.println(%22%3Cbody%3E%22);%0A%09%09out.println(%22%3Cform method=post action=/servlet/LoginAndProcess?event=process%3E%22);%0A%09%09out.println(%22User: %3Cinput type=text name=user%3E%3Cbr%3E%22);%0A%09%09out.println(%22Password: %3Cinput type=password name=password%3E%3Cbr%3E%3Cbr%3E%22);%0A%09%09out.println(%22%3Cinput type=submit value=login%3E%22);%0A%09%09out.println(%22%3C/form%3E%22);%0A%09%09out.println(%22%3C/body%3E%22);%0A%09%09out.println(%22%3C/html%3E%22);%0A%09%09out.close();%0A%09%7D%0A%0A%09public void process(HttpServletRequest request,%0A%09%09%09%09%09%09HttpServletResponse response)%0A%09%09throws ServletException, IOException%0A%09%7B%0A%09%09System.out.println(%22LoginAndProcess.doPost%22);%0A%09%09String user = request.getParameter(%22user%22);%0A%09%09String password = request.getParameter(%22password%22);%0A%09%09if ( user.equals(%22parrt%22) && password.equals(%22foobar%22) ) %7B%0A%09%09%09// all is ok, direct to %22home page%22%0A%09%09%09response.sendRedirect(%22/servlet/RandomPage%22);%0A%09%09%7D%0A%09%09else %7B%0A%09%09%09// oops...back to login.%0A%09%09%09response.sendRedirect(%22/servlet/LoginAndProcess?event=view%22);%0A%09%09%7D%0A%09%7D%0A%7D%0A

add sample code