package com.example.web;

import com.example.model.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

/** Servlet class that performs the request
 * @author Yana Novikova
 * @version A10
 */
public class ScheduleSelect extends HttpServlet {

    /** Database url */
    private String url;
    /** User name */
    private String user;
    /** Password */
    private String pw;

    /** Provides the servlet with the chance to get runtime configuration
     * values and initialize itself. It gets driver URL, username and password
     * from web.xml file
     */
    public void init(ServletConfig cfg) throws ServletException {
	super.init(cfg);
	{
	    ServletContext ctx = getServletContext();

	    //get all information
	    url = ctx.getInitParameter("url");
	    user = ctx.getInitParameter("user");
	    pw = ctx.getInitParameter("passwd");
	}
    }

    /** Performs HTTP POST request */
      public void doPost(HttpServletRequest request,
		       HttpServletResponse response)
	throws IOException, ServletException {
	  String users = request.getParameter("user");

	ScheduleExpert se = new ScheduleExpert();
	List result = se.getNames(url, user, pw);

	request.setAttribute("user", users);
	request.setAttribute("styles", result);
	RequestDispatcher view = request.getRequestDispatcher("lookup_choose.jsp");
	view.forward(request, response);
    }
}
