import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class LoginAndProcess extends HttpServlet {
	public void doGet(HttpServletRequest request,
					  HttpServletResponse response)
		throws ServletException, IOException
	{
		generate(request,response);
	}

	public void doPost(HttpServletRequest request,
					   HttpServletResponse response)
		throws ServletException, IOException
	{
		generate(request,response);
	}

	public void generate(HttpServletRequest request,
						 HttpServletResponse response)
		throws ServletException, IOException
	{
		String event = request.getParameter("event");
		if ( event==null || event.equals("view") ) {
			view(request,response);
		}
		else {
			process(request,response);
		}
	}

	public void view(HttpServletRequest request,
					 HttpServletResponse response)
		throws ServletException, IOException
	{
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		out.println("<html>");
		out.println("<body>");
		out.println("<form method=post action=/servlet/LoginAndProcess?event=process>");
		out.println("User: <input type=text name=user><br>");
		out.println("Password: <input type=password name=password><br><br>");
		out.println("<input type=submit value=login>");
		out.println("</form>");
		out.println("</body>");
		out.println("</html>");
		out.close();
	}

	public void process(HttpServletRequest request,
						HttpServletResponse response)
		throws ServletException, IOException
	{
		System.out.println("LoginAndProcess.doPost");
		String user = request.getParameter("user");
		String password = request.getParameter("password");
		if ( user.equals("parrt") && password.equals("foobar") ) {
			// all is ok, direct to "home page"
			response.sendRedirect("/servlet/RandomPage");
		}
		else {
			// oops...back to login.
			response.sendRedirect("/servlet/LoginAndProcess?event=view");
		}
	}
}

@@ -1,28 +1,85 @@
+import org.eclipse.jetty.servlet.ServletContextHandler;%0A%0A
 import javax.servlet.Servlet
@@ -1250,39 +1250,21 @@
 action=/
-servlet/LoginAndProcess
+login
 ?event=p
@@ -1955,25 +1955,11 @@
 t(%22/
-servlet/RandomPag
+hom
 e%22);
@@ -2031,49 +2031,527 @@
 t(%22/
-servlet/LoginAndProcess?event=view%22);%0A%09%09%7D
+login?event=view%22);%0A%09%09%7D%0A%09%7D%0A%0A%09public static void main(String%5B%5D args) throws Exception %7B%0A%09%09org.eclipse.jetty.server.Server server = new org.eclipse.jetty.server.Server(8080);%0A%09%09// To use sessions, we have to use ServletContextHandler not%0A%09%09// ServletHandler%0A%09%09ServletContextHandler handler = new%0A%09%09            ServletContextHandler(ServletContextHandler.SESSIONS);%0A%09%09server.setHandler(handler);%0A%09%09// only need to register one page.%0A%09%09handler.addServlet(LoginAndProcess.class, %22/login%22);%0A%09%09server.start();%0A%09%09server.join();
 %0A%09%7D%0A

add sample code