package com.wxpn.tutorial.ec.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collection;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wxpn.tutorial.db.ConnectionPool;
import com.wxpn.tutorial.db.DB;
import com.wxpn.tutorial.ec.bean.ECMember;
import com.wxpn.tutorial.ec.bean.ECMemberMgr;

/**
 * Servlet implementation class for Servlet: LoginServlet
 */
public class FindPasswordServlet extends javax.servlet.http.HttpServlet implements
		javax.servlet.Servlet {
	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public FindPasswordServlet() {
		super();
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=GB2312");
		String result = "";

		String logname = request.getParameter("logname");
		String email = request.getParameter("email");
		String problem= request.getParameter("problem");
		String answer= request.getParameter("answer");

		ECMemberMgr mgr = new ECMemberMgr();
		String password = mgr.getPassword(logname, email,problem,answer);
		if (password != null) {
			request.setAttribute("password",password);
		} else{
			request.setAttribute("password","输入的用户名与密码提示问题、答案不匹配，请重试！");
		}
			try {
				request.getRequestDispatcher("/member/findpass.jsp").forward(request,
						response);
			} catch (Throwable t) {
				getServletContext().log(t.getMessage());
			}
		
	}
}